Wednesday, April 29, 2009

How to Show a Mesage Box in ASP.NET

A lot of Developer from windows Platform who are new to Web Development , tries to mimic what they were doing in Windows Development on the Web. Well it would be nice if Microsoft can add this feuture in ASp.net. Message boxes are the way a Developer interect with his or her users. In Windows Application its simple because you just need to call the Function

MessageBox.Show("Your Message here...");

This can still be used in the Web but , your message box will show at the taskbar and this will not be your intentions. To over come this in Asp.net you have to create a Function like this


public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}

and you can call it like this



string strMessage = "You Message here...";
CreateMessageAlert(this.Page, strMessage, "strKey1");


That is Simple.

Vuyiswa Maseko

Tuesday, April 28, 2009

The State Information is Invalid for this Page and might be Corrupted

Some other Errors are not code related and but they can be solved through the code. Am uploading the Xml file to ym DB and am using Infragistics Controls to do this , it will work for very small files but it will give you a problem with a larger Files. Here is the cause

Problem:

This comes, because from version 2.2.2, we made the RadUploadHttpModule parse the files when used with the Cassini web server. I believe you have encountered a similar problem - the request data is not read properly by the RadUploadHttpModule and corrupt ViewState data is passed to the page. and you finnaly get the error

The case-sensitive value that the TemplateSourceDirectory property of a page returns is used to create and to validate the ViewState property for that page. The value of this property for a page depends on the case-sensitive URL that the first user for that page requested. This value is reused for the remaining requests for that page until that page is recompiled. When the page is recompiled, the TemplateSourceDirectory property is re-initialized. If the new value (which is case-sensitive) differs from the previous value, the ViewState validation from the existing clients fails.


The State Information is Invalid for this Page and might be Corrupted

Resolutions:

  1. Someone else reported the same error and seemed to have found a workaround by causing his upload button PostbackUrl to go to the same page like this

btnAddFile.PostBackUrl = "~/NewsAddFiles.aspx?NewsId=" + hiddenNewsId.Value;

2. Download a hotFix http://support.microsoft.com/default.aspx?scid=kb;ko;323744

http://support.microsoft.com/ph/1173#tab0

3: Save the radion button selection and tree control node selection in session variables instead of view state, because the life scope of the view state is only within the page. When user navigates away to a different page, the view state of the previous page is destroyed.

Hope this This Helps

Vuyiswa Maseko