Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use an UpdatePanel properly?

I have an UpdatePanel with some checkboxes in it. I check them, and hit my Save button, but that causes the UpdatePanel to postback (refresh) and sets them all back to blank. The re-drawing method runs before the button code.

What is the correct way to have an UpdatePanel with checkboxes in that you can manipulate?

like image 584
NibblyPig Avatar asked Oct 06 '09 12:10

NibblyPig


2 Answers

Example of code:

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updatePanel1">
    <ContentTemplate>
        <asp:CheckBox runat="server" ID="myCheckBox" Caption="CheckBox"/>
        <asp:Button runat="server" ID="saveButton" 
                   Caption="Save" OnClick="SaveButtonClick"/>
    </ContentTemplate>    
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="saveButton" EventName="Click" />        
    </Triggers>
</asp:UpdatePanel>

Make sure that:

  1. UpdateMode of UpdatePanel is Conditional
  2. SaveButton contained in Triggers-section as ControlID of AsyncPostBackTrigger
like image 166
AndreyAkinshin Avatar answered Sep 28 '22 08:09

AndreyAkinshin


Your code behind should look like:

if(!page.ispostback)
{
   re-drawing();
}

As when you hit Save button your re-drawing() method is called and it again refreshes your checkboxes. Asynchronous postback behaves and hit to page method the same as full postback, but refreshes the values in any updatepanels.

Also check this URL http://ajax.net-tutorials.com/controls/updatepanel-control/

like image 21
Muhammad Akhtar Avatar answered Sep 28 '22 08:09

Muhammad Akhtar