When this error comes, put enableViewStateMac=”false” in the tag either in the web.config or in the page where you get this error.
Archive for the ‘asp.net’ Category
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay
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.
Login failed for user ‘IIS APPPOOL\DefaultAppPool’
I got this issue in my system using Windows 7 Ultimate when trying to run a site which is configured to run in IIS. You can get the solution for this from the following link
specifying ValidationGroup in Page_ClientValidate function
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
To access control of a User Control from an aspx page
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”;
}
}
DateTime.ToString formats
From the following link, you can see all types of formats we can get using DateTime.ToString() method.
More Info
Converting DateTime to ShortDate in SQL
When you need to get datetime field value in short date, use the following:
To get today’s date in YYYYMMDD format:
SELECT CONVERT(CHAR(8), GETDATE(), 112)
To get today’s date in mm/dd/yyyy:
CONVERT(VARCHAR(10), GETDATE(), 101)
Showing JavaScript confirmation after Client Validation
Some time we use javascript to display alert or confirmation box on button click. But, if we are using ajax validation on that page, that will work only after post back if we click ok on the confirmation box. So, to display the confirmation box, only if the page is valid, Check this link
Finding the Public Key Token of dll
You have to add assembly to web.config like the following
How to get the public token of a dll to add it to web.config?
Learn More
Ajax and UpdatePanel performance improvement
Most of the newbie programmers like me are ajaxifying a site by putting updatepanels all over the site. Now, I came to know that, putting updatepanel will not help you to improve your site’s speed. We are using it, since it is very easy. You can understand why ajax updatenpanels should be avoided from the following link
If you still want to use updatepanel, check the following link to speed up the updatepanel performance.
Also, you can use a dll, scriptreferenceprofiler, to find the ajax scripts used in a page and combine them, so that, only that script requests will be used in that specific page, which reduces the loading time. You can understand how to use it from the following msdn video.
You can download ScriptReferenceProfile from the following url
Download
Use them as follows
Add reference to the dll.
<%@ Register Assembly="ScriptReferenceProfiler" Namespace="ScriptReferenceProfiler" TagPrefix="cc1" %>