Wednesday, May 19, 2010

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

10:52 PM Posted by Unknown , No comments
I have got this issue many times, when I try to send email using smtp. There can be several causes for this. You have to allow relay for mail to be sent to outside servers like gmail.com. For sending mail within your server you don't have to do this. You can find some helps from the following links:
Help1
Help2
Help3

The code I have used is given below:

using System.Net.Mail;


SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
smtpClient.Port = 25;
smtpClient.Host = "smtp.domain.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("webmail username", "webmail password");
message.From = new MailAddress("webmail username");
message.To.Add("test@gmail.com");
string emailBody = "Hi,

Welcome

";
message.Body = emailBody;
message.Subject = "testing";
message.IsBodyHtml = true;
smtpClient.Send(message);

But, after making the changes on the server, as specified on the above links, I was still getting the same error. Then I added the following line in between the above code.
smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;

Then the error was gone.

Friday, April 23, 2010

Wednesday, March 31, 2010

Grouping Gridview

7:31 PM Posted by Unknown No comments
Some times we want to group gridview. ZNet is a good control for this use.
ZNet
We can use this for grouping and also for the comparison.

Saturday, March 13, 2010

specifying ValidationGroup in Page_ClientValidate function

1:41 AM Posted by Unknown , No comments
Hi,

We know that, Page_ClientValidate function tests if all controls meet asp.net validation criteria. This function is provided by asp.net. But, if we use more than, one validation group in the page, we may have to specify the validation group, we want to validate. For that, give like given below:
Page_ClientValidate('ValGroupName')

Then, it will validate only for that validation group

Friday, March 5, 2010

The Controls collection cannot be modified because the control contains code blocks

10:26 AM Posted by Unknown No comments
This is a common error. It occurs when we use <%= %> tag inside the head tag with runat="server" given. You can get rid of the error by removing the runat="server" from the head tag. But, sometimes, we want to keep that. We can use <%# %> instead of <%= %>. But, then, the value may not get bound and we may not get the value of the expression. So, when we use <%# %>, we have to add Page.Header.DataBind(); in the Page Load event.
More Info

Wednesday, March 3, 2010

To access control of a User Control from an aspx page

9:44 AM Posted by Unknown No comments
Whenever you want to access the controls of an usercontrol, create public properties for those controls in your usercontrols and you could easily access them in your .aspx page.

Here it goes how...
UserControl.

1 public partial class WebUserControl : System.Web.UI.UserControl
2 {
3 public string TextBoxValue {
4 get { return TextBox1.Text; }
5 set { TextBox1.Text = value; }
6 }
7 protected void Page_Load(object sender, EventArgs e) {
8
9 }
10 }

In your .aspx page you can access it either html or code
<%@ Register TagPrefix="DS" TagName="TB" Src="~/WebUserControl.ascx" %>




or

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
myTB1.TextBoxValue = "Sample Text";
}
}

Friday, February 26, 2010