开发者

radiobutton checked status on asp:linkbutton postback

开发者 https://www.devze.com 2022-12-08 07:08 出处:网络
I have four radiobuttons inside a repeater control whichby itself is inside an update panel // code is something like this

I have four radiobuttons inside a repeater control which by itself is inside an update panel

// code is something like this

`<asp:update panel ..>
...
<asp:Repeater>
..
<asp:checkbox>
..
..
</asp:update panel ..>
<asp:LinkButton ID="next2" runat="server" CssClass="button_Submit" Font-Bold="true"    OnClick="next_ServerClick" Text="Submit"> 
<asp:ImageButton ID="next" ImageUrl="~/images/newSummary.jpg" runat="server" OnClick="next_ServerClick" ImageAlign="Middle"/>
protected void next_ServerClick(object sender, EventArgs e)
{
foreach (System.Web.UI.WebControls.RepeaterItem Item in repeatercontrol.Items)
{
   chkbox = ((CheckBox)Item.FindControl(chkboxName));
   if (chkbox.checked)
   {
    ...
   }
}
}`

I select one of the checkboxes and when i click image button, am able to get the correct status (checked =true) .

But when i use link button, it is always coming as开发者_如何学Go checked =false as if the selection did not register.

Any ideas on why this is happening?


You need to register the linkbutton click event as a trigger in the update panel. See example below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
    <ContentTemplate>

        ...

    </ContentTemplate>

    <Triggers>

        <asp:AsyncPostBackTrigger ControlID="LinkButtonID" EventName="Click" />

    </Triggers>

</asp:UpdatePanel>


Without seeing the code, the only reason the controls would be incorrect is if you are checking them in the Page Life Cycle before the ViewState is loaded.

EDIT: Use separate event declarations and centralize the lookup logic:

    protected void LinkButton1_Click(object sender, EventArgs e)
    {

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消