I need help...
I am trying to set the Viewstate of a var on an onclick event and let the
page post back to get the new value. When i click the button, the first time
though (on the post back) it reads empty string. On subsequent clicks it
seems to be on off the actual value I have assigned to the ViewState
variable.
Some psudio code below:
btnPush = (string)ViewState["btnPush"];
topicCount = (int)ViewState["topicCount"];
if (btnPush == "")
{
curNum = Convert.ToInt32(Request.QueryString["CurNum"]);
topicID = Convert.ToInt32(Request.QueryString["TopicID"]);
}//end if (btnPush.Length == 0)
if (btnPush == "Next")
{
curNum = Convert.ToInt32(ViewState["CurNum"]) + 1;
topicID = Convert.ToInt32(ViewState["NTopID"]);
}//end if (btnPush == "Next")
if (btnPush == "Prev")
{
curNum = Convert.ToInt32(ViewState["CurNum"]) - 1;
topicID = Convert.ToInt32(ViewState["PTopID"]);
}//end if (btnPush == "Prev")
private void NextButton_Click(object sender, System.EventArgs e)
{
ViewState["btnPush"] = "Next";
ViewState["TopicID"] = Convert.ToInt32(ViewState["PTopID"]);
}
The fiirst time i click the Next button the variable btnPush still reads as
"". The second time it reads the button value I pushed previously, etc. I
seems to always be one behind the actual value set on the click event. Any
ideas? I am totally lost on this one.
James