Search This Blog

Mar 5, 2010

Generating system exception in asp.net

CODE FOR GENERATING SYSTEM EXCEPTION IN ASP.NET


FOLLOWING STEPS U NEED TO FOLLOW :
  • Open the vs 05.
  • Now,create new website.this will open the default page.
  • Add a textbox and button on the same.
button1_click(object sender eventargs e)
{
if(TextBox1.Text.Length == 0)
{
throw new SystemException();
or u can write :
throw new ArgumentNullException();
}  
  • Add new web form by right clicking on the solution explorer on the url of the web application.
  • Add a label on the same.
  • Now do the following code on the page load of the label click:



if(Page.PreviousPage != null)
{
TextBox t = (TextBox)Page.PreviousPage.FindControl("TextBox1");
if(t != null)
{
Label1.Text = t.Text;
}
}
  • Now add the attribute on the source window of web form 2 in the label part:
PostBackUrl = "Default.aspx"
  • Now add the directive after the page directive in the source window of the default2.aspx :
<@PreviousPageType VirtualPath = "~/Default.aspx">