473,418 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

ViewState button event....stumped

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
Nov 17 '05 #1
2 1503
James:

I am not sure where (what event) you are trying to read the ViewState value,
but for informational purposes the Page Init and Load events occur before
the control postback event procedures. This is one possible explanation for
why you are one step behind in the value.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"James Glover" <ec****@gmail.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2
Ahh, that's right. Thank you. I think it was a case of over thinking the
code. I have it fixed now and I thank you again.
"David Lloyd" <Da***@NoSpamPlease.com> wrote in message
news:qs********************@bignews6.bellsouth.net ...
James:

I am not sure where (what event) you are trying to read the ViewState
value,
but for informational purposes the Page Init and Load events occur before
the control postback event procedures. This is one possible explanation
for
why you are one step behind in the value.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or
warranties.
"James Glover" <ec****@gmail.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
0
by: seven | last post by:
I have a base page with an HTMLForm object (added to the base page control heiarchy during Init). In the design of pages derived from this base page, I can choose to create controls and add them...
1
by: Jonathan | last post by:
Hello, I'm writed a WebCustomControl but I can't mantain the viewstate this is the code of my WebCustomContol: public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
1
by: pbb | last post by:
I'm creating a set of dynamic controls on a webpage by calling my BuildControls sub in the Page_Init sub. I recreate the controls by calling the BuildControls sub in the LoadViewState override...
5
by: Frank | last post by:
I'm really stumped here. I have a couple pages where I'm using a datagrid and a custom paging solution. I store the current page, sort column, etc in the ViewState of the page. When a column is...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.