开发者

radiobutton checked status on asp:linkbutton postback

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜