Bugs found in Asp.Net application (SERIOUS)

W

WJ

This post is a follow up from the original post dated Oct 16, 2004 "I have
this problem, pls help!" created by Paul FI.
These bugs are rather serious and we would like to know how to get around.

Environment: Windows XP Pro. IIS-5 and Sp2.
Visual Studio.Net 2003 EA edition.
..NetFW 1.1

Here goes:

The followings are steps to reproduce two serious bugs found by Paul and
John within Asp.Net application. The application is a c# and consists of the
following items:

1. Web site: http://LocalHost/tBug
2. Four Asp.Net forms: WebForm1.Aspx (Default page), WebForm2.Aspx,
WebForm3.Aspx, and WebForm4.Aspx

Steps:

1. Create a new c-sharp (c#) Asp.Net web Project called tBug.
2. Drop a "Drop Down List Component" on WebForm1.aspx and call it "DDL", and
enable its "AutoPostBack".
3. Add 3 items to the DDL called Test1, Test2 and Test3 for their "Text"
property. Assign 1, 2 and 3 to their "Value" property accordingly.
4. Drop a Label compoment beside the DDL.
5. Drop two Button components on WebForm1 under the DDL and call them
Button1(Text=ToWebForm2) & Button2 (Text=ToWebForm3).
6. Double-Click on the WebForm1 itself and copy this code below onto your
WebForm1.onPage Load event:

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text="Welcome to New tBug";
return;
}

Label1.Text="I am Back";
}

7. Double-Click on the WebForm1.DDL and copy this code below onto your
WebForm1.DDL_SelectedIndexChanged event:

private void DDL_SelectedIndexChanged(object sender, System.EventArgs
e)
{
Response.Redirect("WebForm4.aspx");
}


8. Double-Click on the WebForm1.Button1 and copy this code below onto your
WebForm1.Button1_Click event:

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}

9. Double-Click on the WebForm1.Button2 and copy this code below onto your
WebForm1.Button2_Click event:

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm3.aspx");
}


10. On the Solution Explorer, right-click on the "tBug" project and select
Add/New Asp.Net Form. Name it "WebForm2".
11. Repeat Step 10 above for WebForm3 and WebForm4.

12. Bringup WebForm2 and drop a Label component on its design surface and
assign "This is WebForm2" to its Text property.
13. Bringup WebForm3 and drop a Label component on its design surface and
assign "This is WebForm3" to its Text property.
14. Bringup WebForm4 and drop a Label component on its design surface and
assign "This is WebForm4" to its Text property.

15. Build the sulution and run it.

How to see the described BUGS:

16. Once the application is shown on the MS/IE, you should see the
Label1.Text has "Welcome to new tBug" as expected.
17. Select "Test2" from the DDL. This will bring you to WebForm4.aspx as
expected.
18. Click the "Back" button from the MS/IE tool bar. This will bring you
back to WebForm1.aspx as expected.

19. Click the "ToWebForm2 or 3" button on WebForm1, this should bring you to
"WebForm2 or 3" but "WebForm4" is shown instead.This is the "BUG" that Paul
FI talked about.

20. Click the "Back" button to go back to WebForm1 as expected.
21. Select "Test1" from the DDL, this should bring you to WebForm4, instead,
it shows "I am Back" on Webform1. This is a new BUG I found.

*****************************************************
Below is a complete c# code-behind for WebForm1.aspx.
*****************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace tBug
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList ddl;

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text="Welcome to New tBug";
return;
}

Label1.Text="I am Back";
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.ddl.SelectedIndexChanged += new
System.EventHandler(this.ddl_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

private void ddl_SelectedIndexChanged(object sender, System.EventArgs
e)
{
Response.Redirect("WebForm4.aspx");
}

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm3.aspx");
}

}
}

Thanks for your help,

John Webb
 
G

Guest

WJ said:
This post is a follow up from the original post dated Oct 16, 2004 "I have
this problem, pls help!" created by Paul FI.
These bugs are rather serious and we would like to know how to get around.

Environment: Windows XP Pro. IIS-5 and Sp2.
Visual Studio.Net 2003 EA edition.
..NetFW 1.1

Here goes:

The followings are steps to reproduce two serious bugs found by Paul and
John within Asp.Net application. The application is a c# and consists of the
following items:

1. Web site: http://LocalHost/tBug
2. Four Asp.Net forms: WebForm1.Aspx (Default page), WebForm2.Aspx,
WebForm3.Aspx, and WebForm4.Aspx

Steps:

1. Create a new c-sharp (c#) Asp.Net web Project called tBug.
2. Drop a "Drop Down List Component" on WebForm1.aspx and call it "DDL", and
enable its "AutoPostBack".
3. Add 3 items to the DDL called Test1, Test2 and Test3 for their "Text"
property. Assign 1, 2 and 3 to their "Value" property accordingly.
4. Drop a Label compoment beside the DDL.
5. Drop two Button components on WebForm1 under the DDL and call them
Button1(Text=ToWebForm2) & Button2 (Text=ToWebForm3).
6. Double-Click on the WebForm1 itself and copy this code below onto your
WebForm1.onPage Load event:

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text="Welcome to New tBug";
return;
}

Label1.Text="I am Back";
}

7. Double-Click on the WebForm1.DDL and copy this code below onto your
WebForm1.DDL_SelectedIndexChanged event:

private void DDL_SelectedIndexChanged(object sender, System.EventArgs
e)
{
Response.Redirect("WebForm4.aspx");
}


8. Double-Click on the WebForm1.Button1 and copy this code below onto your
WebForm1.Button1_Click event:

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}

9. Double-Click on the WebForm1.Button2 and copy this code below onto your
WebForm1.Button2_Click event:

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm3.aspx");
}


10. On the Solution Explorer, right-click on the "tBug" project and select
Add/New Asp.Net Form. Name it "WebForm2".
11. Repeat Step 10 above for WebForm3 and WebForm4.

12. Bringup WebForm2 and drop a Label component on its design surface and
assign "This is WebForm2" to its Text property.
13. Bringup WebForm3 and drop a Label component on its design surface and
assign "This is WebForm3" to its Text property.
14. Bringup WebForm4 and drop a Label component on its design surface and
assign "This is WebForm4" to its Text property.

15. Build the sulution and run it.

How to see the described BUGS:

16. Once the application is shown on the MS/IE, you should see the
Label1.Text has "Welcome to new tBug" as expected.
17. Select "Test2" from the DDL. This will bring you to WebForm4.aspx as
expected.
18. Click the "Back" button from the MS/IE tool bar. This will bring you
back to WebForm1.aspx as expected.

19. Click the "ToWebForm2 or 3" button on WebForm1, this should bring you to
"WebForm2 or 3" but "WebForm4" is shown instead.This is the "BUG" that Paul
FI talked about.

20. Click the "Back" button to go back to WebForm1 as expected.
21. Select "Test1" from the DDL, this should bring you to WebForm4, instead,
it shows "I am Back" on Webform1. This is a new BUG I found.

*****************************************************
Below is a complete c# code-behind for WebForm1.aspx.
*****************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace tBug
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList ddl;

private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text="Welcome to New tBug";
return;
}

Label1.Text="I am Back";
}

override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.ddl.SelectedIndexChanged += new
System.EventHandler(this.ddl_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

private void ddl_SelectedIndexChanged(object sender, System.EventArgs
e)
{
Response.Redirect("WebForm4.aspx");
}

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm2.aspx");
}

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm3.aspx");
}

}
}

Thanks for your help,

John Webb

This is a logical consequence of how the Changed events are fired and how IE
reloads pages when using the Back button. While this behavior might not be
what you wanted or expected, it doesn't represent a flaw in any particular
product, just a situation you'll have to code around to get the behavior
you're looking for. I'd suggest reading up on the Viewstate and how it
relates to tracking control values and firing the Changed events. Also note
that postback events do not have a guaranteed order, so you can never
definitively say that the button click event will execute before the list
change event (unless you do some hacking in the handlers to enforce an
ordering, which I wouldn't recommend).
For the time being, I'd suggest using caching settings to request that the
browser not cache Webform1.aspx. (Note that I say request. You cannot *force*
the browser not to cache the page, only ask it not to.) There have been a few
posts on this group on how to do this; a search should turn them up.
 
W

WJ

Though I never run into the problem. But I do tell my clients not to click
on the "Back" button, instead they always click on my application's Url Link
provided to them. This way, the described bug can be avoided without
addtional coding. As for other bug, I just plug in a dummy item that sits on
top of the drop down list and it will never be selected.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top