473,394 Members | 1,811 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,394 software developers and data experts.

How does the viewstate work?

See below for example code.

My problem is that when the drop down list posts back the event handler for
the check box also executed. I have no idea why this happens?

The only odd thing I can see is [using the trace directive] the viewstate
size bytes of the check box is 0 but after a post back it is non zero.

Any help and advice most welcome!

<!-- Begin ASP.NET Code -->
......
<asp:dropdownlist runat="server" id="lstFontProperties" autopostback="True" />
<asp:checkbox runat="server" id="chkLegend" text="Show Legend"
autopostback="True" />
<asp:textbox runat="server" id="txtLegendTitle" visible="false" />
......
<!-- End ASP.NET Code -->

My page uses code behind and both the drop down list and the check box have
an event handler associated with it self. The textbox only appears when the
check box is checked (txtLegendTitle.Visible = chkLegend.Checked).
Nov 19 '05 #1
3 1268
We've copied your code and if we wire up event handlers to the dropdownlist
and checkbox the event handlers are executed correctly, only one of them at a
time. The fact that the viewstate is 0 at the beginning and later becomes non
zero is insignificant. After the first postback it contains 36 bytes (in our
case) containing the state of the checkbox (either 'on' or 'off'). This
viewstate size doesn't change when the checkbox becomes checked. The one
thing that differs between a checkbox which is checked and one which isn't is
the render size. Maybe you should try again on a new page, as the asp.net
code you've posted is correct. Hth.

Kind regards,
Nikander & Margriet Bruggeman

"Naeem Sarfraz" wrote:
See below for example code.

My problem is that when the drop down list posts back the event handler for
the check box also executed. I have no idea why this happens?

The only odd thing I can see is [using the trace directive] the viewstate
size bytes of the check box is 0 but after a post back it is non zero.

Any help and advice most welcome!

<!-- Begin ASP.NET Code -->
.....
<asp:dropdownlist runat="server" id="lstFontProperties" autopostback="True" />
<asp:checkbox runat="server" id="chkLegend" text="Show Legend"
autopostback="True" />
<asp:textbox runat="server" id="txtLegendTitle" visible="false" />
.....
<!-- End ASP.NET Code -->

My page uses code behind and both the drop down list and the check box have
an event handler associated with it self. The textbox only appears when the
check box is checked (txtLegendTitle.Visible = chkLegend.Checked).

Nov 19 '05 #2
Have you accidentally wired up both controls to the same event?

Have a look in the code behind method InitializeComponent

MattC

"Naeem Sarfraz" <Na**********@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
See below for example code.

My problem is that when the drop down list posts back the event handler
for
the check box also executed. I have no idea why this happens?

The only odd thing I can see is [using the trace directive] the viewstate
size bytes of the check box is 0 but after a post back it is non zero.

Any help and advice most welcome!

<!-- Begin ASP.NET Code -->
.....
<asp:dropdownlist runat="server" id="lstFontProperties"
autopostback="True" />
<asp:checkbox runat="server" id="chkLegend" text="Show Legend"
autopostback="True" />
<asp:textbox runat="server" id="txtLegendTitle" visible="false" />
.....
<!-- End ASP.NET Code -->

My page uses code behind and both the drop down list and the check box
have
an event handler associated with it self. The textbox only appears when
the
check box is checked (txtLegendTitle.Visible = chkLegend.Checked).

Nov 19 '05 #3
I've had a look at the InitializeComponent and no they haven't been wired up
to the same control.

After having stepped through the code I see the list event handler being
fired then immediately after the event handler for the checkbox executes.

"MattC" wrote:
Have you accidentally wired up both controls to the same event?

Have a look in the code behind method InitializeComponent

MattC

"Naeem Sarfraz" <Na**********@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
See below for example code.

My problem is that when the drop down list posts back the event handler
for
the check box also executed. I have no idea why this happens?

The only odd thing I can see is [using the trace directive] the viewstate
size bytes of the check box is 0 but after a post back it is non zero.

Any help and advice most welcome!

<!-- Begin ASP.NET Code -->
.....
<asp:dropdownlist runat="server" id="lstFontProperties"
autopostback="True" />
<asp:checkbox runat="server" id="chkLegend" text="Show Legend"
autopostback="True" />
<asp:textbox runat="server" id="txtLegendTitle" visible="false" />
.....
<!-- End ASP.NET Code -->

My page uses code behind and both the drop down list and the check box
have
an event handler associated with it self. The textbox only appears when
the
check box is checked (txtLegendTitle.Visible = chkLegend.Checked).


Nov 19 '05 #4

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

Similar topics

5
by: Christian | last post by:
Hi, Viewstate of WebUserControl does NOT work although the 'EnableViewstate'-property of the usercontrol is set to true Description : Using ASP.Net : I have a created a WebPage with 2...
2
by: Christian | last post by:
Hi, Viewstate of WebUserControl does NOT work although the 'EnableViewstate'-property of the usercontrol is set to true Description : Using ASP.Net : I have a created a WebPage with 2...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
6
by: Henri | last post by:
Very strange problem : if I write: <asp:TextBox runat="server" id="myBox" /> the control's ViewState stays always empty, so it loses its properties if it's not always displayed. But if I...
1
by: Secret Squirrel | last post by:
Hi, 1) So I have a Textbox server side control. I edit the value in the control client side, in my browser, and postback by clicking a button. Now on the server-side, the request is...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
10
by: Mr Newbie | last post by:
DropDown lists and Listboxes do not appear in the list of controls and values passed back to the server on PostBack in Request.Form object. Can someone confirm this to be correct and possibly...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
7
by: GS | last post by:
Hello, I'm receiving The state information is invalid for this page and might be corrupted error message when running code below. This happens on second post back. Why is it happening? My...
6
by: mosscliffe | last post by:
I am testing for how/when a page is posted back and I decided to use a ViewState variable in PageLoad to set up a counter, but it appears, the ViewState is cleared on each PageLoad. So then I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.