views:

2894

answers:

5

I seem to have no end of problems with them.

I have an update panel with some check boxes in. I check them, and hit my Save button, but it causes the update panel 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?

Edit: I think the problem could be a fundamental design one. I really need a full tutorial of how to use updatepanels properly.

+1  A: 

Make sure the Save button is inside the Update Panel, for a start, and if not, that is designated as a Trigger for the Update Panel, in the <Triggers> section of the Update Panel.

<asp:UpdatePanel ID="MyControlPanel" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="SaveButton" />
    </Triggers>
    <ContentTemplate> ...

Can you show some code for your UpdatePanel?

Rafe Lavelle
+1  A: 

your code should be look like

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

As when you hit Save button your re-drawing() method called and it again refresh your checkboxes. Asynchronous postback behave and hit to page method same like full postback but refreshes value in updatepanels

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

Muhammad Akhtar
That makes sense, but it seems to clear the panel automatically. If I put "if (condition) return;" as the first line of my update panels onload method, it ends up wiping it.
SLC
show ur code.....
Muhammad Akhtar
A: 

If you use server controls to render checkboxes you should add EnableViewState="true" attribute to these controls and update panel.

If you have checkboxes that are not server controls, then remove them from update panel, include only server controls inside. This leads to keeping several updates panel on a page that's usually not a big issue.

terR0Q
A: 

Add a ScriptManager object to your page if you do not have one. Set EnablePartialRendering="true". Put your UpdatePanel anywhere else on the page and place the content you want ajaxified within a tag within your UpdatePanel.

Matt
+1  A: 

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
DreamWalker
I think the conditional thing may be causing it. I reckon I can solve it now, thanks.
SLC
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
SLC
Hmm ... This is very strange. Can you write description of your ScriptManager?
DreamWalker
My page was such a mess from trying to debug it that I started over, I'll post again if I have any problems. Thanks for your help.
SLC