CheckBox loses state with when HyperLink clicked

M

mschoup

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>
 
A

Andy Fish

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top