views:

234

answers:

2

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 checked =false as if the selection did not register.

Any ideas on why this is happening?

A: 

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>
rip
I tried your suggestion and it still did not work.As I have mentioned, I am able to get value when I use Image button (and it is not added as a trigger)
jg
A: 

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)
    {

    }
rick schott
I am checking the values in the onclick event handler for the buttons. So, Viewstate should have been loaded by then, correct ?
jg
Yes, it should be there in those events.
rick schott
I know i keep asking, but it would be helpful to see how you declare these events and the actual code-behind. Things like this tend to be simple oversight.
rick schott
//declaration code<asp:LinkButton ID="next2" runat="server" CssClass="button_Submit" Font-Bold="true" OnClick="next_ServerClick" Text="Submit"><asp:ImageButton ID="next" ImageUrl="~/Includes/images/newSummary.jpg" runat="server" OnClick="next_ServerClick" ImageAlign="Middle"/>// event handlerprotected void linkButton_Click(object sender, EventArgs e) { // code above }
jg