CheckBox loses state with when HyperLink clicked

Discussion in 'ASP .Net' started by mschoup@excite.com, Mar 15, 2005.

  1. Guest

    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>
     
    , Mar 15, 2005
    #1
    1. Advertising

  2. Andy Fish Guest

    <> wrote in message
    news:...
    >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>
    >
     
    Andy Fish, Mar 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    1
    Views:
    983
    Ken Varn
    Aug 19, 2005
  2. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    849
    David Wier
    Oct 6, 2006
  3. =?Utf-8?B?QnJpYW4=?=
    Replies:
    1
    Views:
    558
  4. Replies:
    0
    Views:
    732
  5. Joey Pang
    Replies:
    4
    Views:
    539
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page