By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

CheckBox loses state with when HyperLink clicked

P: n/a
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton,
and two CheckBoxes. When I select a CheckBox and then click the
LinkButton, the CheckBox retains state. When I select the CheckBox and
click the HyperLink (NavigateURL set to WebForm1.aspx), the CheckBox
lost it's state.

I would assume that this is by design (now that I read ASP.NET in a
nutshell) where it describes a HyperLink control action as 'navigates
from one page to another when clicked' whereas the LinkButton action is
described as 'posts a form to the server when clicked.' Just wanted to
confirm if anyone has seen this before and if this is indeed what I'm
running into. Thanks.

WebForm1.aspx
<%@ Page language="c#"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
<P>
<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="WebForm1.aspx">HyperLink</asp:HyperLink>
<asp:LinkButton id="LinkButton1"
runat="server">LinkButton</asp:LinkButton></P>
<P>
<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
<asp:CheckBox id="CheckBox2" runat="server"></asp:CheckBox></P>
</form>
</body>
</HTML>

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<ms*****@excite.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton,
and two CheckBoxes. When I select a CheckBox and then click the
LinkButton, the CheckBox retains state. When I select the CheckBox and
click the HyperLink (NavigateURL set to WebForm1.aspx), the CheckBox
lost it's state.

I would assume that this is by design (now that I read ASP.NET in a
nutshell) where it describes a HyperLink control action as 'navigates
from one page to another when clicked' whereas the LinkButton action is
described as 'posts a form to the server when clicked.' Just wanted to
confirm if anyone has seen this before and if this is indeed what I'm
running into. Thanks.
yes, you are correct. clicking the hyperlink simply navigates the browser to
a page. the fact that it's the same page you are already on is irrelevant.
it's just the same as if you typed in the page URL into the browser.

clicking a linkbutton causes a postback, i.e. it posts a form with all
controls back to the current page, so any control values are passed through.
In fact, postback is much more powerful than a normal post, because it uses
a thing called viewstate to maintain the state of controls on the page.

WebForm1.aspx
<%@ Page language="c#"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="WebForm1" method="post" runat="server">
<P>
<asp:HyperLink id="HyperLink1" runat="server"
NavigateUrl="WebForm1.aspx">HyperLink</asp:HyperLink>
<asp:LinkButton id="LinkButton1"
runat="server">LinkButton</asp:LinkButton></P>
<P>
<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
<asp:CheckBox id="CheckBox2" runat="server"></asp:CheckBox></P>
</form>
</body>
</HTML>

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.