Issue with viewstate? or something else?
-
Well, having fixed my problem with caching (or so I thought) by deleting an old website and re-publishing it, I now have a new set of fun problems. I suspect I've caused them whilst trying to force the new version of a page through. A different page is now misbehaving. I have a button which when clicked, changes the datasource for a gridview based on it's own text, then changes it's own text (so that next time it is clicked it will perform the other action, and change it's text back again). However now, although the first click works ok* when clicked again it fires as though it has the same text.
protected void btn_switchallorown_Click(object sender, EventArgs e)
{
// check which to switch to
switch (btn_switchallorown.Text)
{
case "Show queued requests for ALL departments":
// change SQL command
// change button text
btn_switchallorown.Text = btn_switchallorown.Text.Replace("ALL departments", "YOUR department");
// change empty data text
break;
case "Show queued requests for YOUR department":
// change SQL command
// change button text
btn_switchallorown.Text = btn_switchallorown.Text.Replace("YOUR department", "ALL departments");
// change empty data text
break;
default:
break;
}
// refresh both gridviews
gvw_Queued_Requests.DataBind();
gvw_totals.DataBind();
}Can anyone suggest what I may have broken? This all worked quite happily before? I have tried re-enabling the viewstate but no joy... * except that a tree-view used for navigation collapses to it's root node (never did before).
-
Well, having fixed my problem with caching (or so I thought) by deleting an old website and re-publishing it, I now have a new set of fun problems. I suspect I've caused them whilst trying to force the new version of a page through. A different page is now misbehaving. I have a button which when clicked, changes the datasource for a gridview based on it's own text, then changes it's own text (so that next time it is clicked it will perform the other action, and change it's text back again). However now, although the first click works ok* when clicked again it fires as though it has the same text.
protected void btn_switchallorown_Click(object sender, EventArgs e)
{
// check which to switch to
switch (btn_switchallorown.Text)
{
case "Show queued requests for ALL departments":
// change SQL command
// change button text
btn_switchallorown.Text = btn_switchallorown.Text.Replace("ALL departments", "YOUR department");
// change empty data text
break;
case "Show queued requests for YOUR department":
// change SQL command
// change button text
btn_switchallorown.Text = btn_switchallorown.Text.Replace("YOUR department", "ALL departments");
// change empty data text
break;
default:
break;
}
// refresh both gridviews
gvw_Queued_Requests.DataBind();
gvw_totals.DataBind();
}Can anyone suggest what I may have broken? This all worked quite happily before? I have tried re-enabling the viewstate but no joy... * except that a tree-view used for navigation collapses to it's root node (never did before).
Have you tried setting a breakpoint to see what's happening ? This code does n't change the datasource at all, it just changes the button text and rebinds to the same sources they have.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Have you tried setting a breakpoint to see what's happening ? This code does n't change the datasource at all, it just changes the button text and rebinds to the same sources they have.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Yes - I set a breakpoint at the beginning of this event handler - I have removed the sql changes for clarity brevity :) The issue I have is that the first time the event fires, the text displayed is changed (as expected). The second time the button is clicked, the event fires but the button text (which I am using in the switch) remains the same as the first click, triggering the same case again. I think the issue is something to do with the postback - the navigation tree collapses on postback. My Page_Load event is:
protected void Page_Load(object sender, EventArgs e)
{
// on first load of page
if (!IsPostBack)
{
if (User.Identity.Name != "")
{
if (Session["userName"] == null)
Session["userName"] = Requestor.user_name(User.Identity.Name, 3);
if (Session["deptname"] == null)
Session["deptName"] = Requestor.dept_name(Session["userName"].ToString());// check user's department string deptname = Session\["deptName"\].ToString(); if (!Requestor.Valid\_User(User.Identity.Name)) Response.Redirect("dberror.htm"); else { // Calls a static method to populate the navigation treeview Navigator.FillTreeMenu(NavTree, deptname); } // displays a personalised Welcome message lbl\_User.Text = Requestor.user\_name(User.Identity.Name, 1); } else Response.Redirect("usernameerror.aspx"); // set up Queued data source SQLQueued.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; SQLQueued.SelectCommand = "cp\_Get\_Queued\_Info"; // Refresh datagrid showing outstanding totals gvw\_totals.DataBind(); } }
In addition to the button misbehaviour, lbl_User.Text gets blanked. I think it has to be a viewstate/caching/compilation thing..?
-
Yes - I set a breakpoint at the beginning of this event handler - I have removed the sql changes for clarity brevity :) The issue I have is that the first time the event fires, the text displayed is changed (as expected). The second time the button is clicked, the event fires but the button text (which I am using in the switch) remains the same as the first click, triggering the same case again. I think the issue is something to do with the postback - the navigation tree collapses on postback. My Page_Load event is:
protected void Page_Load(object sender, EventArgs e)
{
// on first load of page
if (!IsPostBack)
{
if (User.Identity.Name != "")
{
if (Session["userName"] == null)
Session["userName"] = Requestor.user_name(User.Identity.Name, 3);
if (Session["deptname"] == null)
Session["deptName"] = Requestor.dept_name(Session["userName"].ToString());// check user's department string deptname = Session\["deptName"\].ToString(); if (!Requestor.Valid\_User(User.Identity.Name)) Response.Redirect("dberror.htm"); else { // Calls a static method to populate the navigation treeview Navigator.FillTreeMenu(NavTree, deptname); } // displays a personalised Welcome message lbl\_User.Text = Requestor.user\_name(User.Identity.Name, 1); } else Response.Redirect("usernameerror.aspx"); // set up Queued data source SQLQueued.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; SQLQueued.SelectCommand = "cp\_Get\_Queued\_Info"; // Refresh datagrid showing outstanding totals gvw\_totals.DataBind(); } }
In addition to the button misbehaviour, lbl_User.Text gets blanked. I think it has to be a viewstate/caching/compilation thing..?
OK - "problem" solved. It was a viewstate issue. Some idiot :-O had discovered that disabling the viewstate on a slow-loading page improved performance. And decided to do the same thing on every page. Including the Master Pages. Which is why enabling/disabling the viewstate on the content page did pretty much zip. My apologies for wasting your valuable time. Of course had I been documenting my modifications as I went along, I might have twigged a little quicker...