Wednesday, March 21, 2012

Is autopostback=true required on checkboxes for asyncpostbacks

My checkbox will only do postbacks when autopostback=true even when i have defined anAsyncPostBackTrigger trigger for the update panel. Is this behavior by design (see code below) ?

Thanks,

Brent

------

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajax" %>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<body>

<formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"/><br/><asp:UpdatePanelID="UpdatePanel1"runat="server"ChildrenAsTriggers="False"UpdateMode="Conditional"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label"Width="94px"></asp:Label><br/><asp:checkboxID="chk"runat="server"Text="Button"OnCheckedChanged="chk_CheckedChanged"/><br/><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/><br/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="chk"EventName="CheckedChanged"/></Triggers></asp:UpdatePanel><br/><asp:LabelID="Label2"runat="server"Text="Label"Width="91px"></asp:Label></div></form>

</

body>

</

html>

Public

PartialClass ajaxInherits System.Web.UI.PageProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

Label1.Text = Now.ToLongTimeString

Label2.Text = Now.ToLongTimeString

EndSubProtectedSub Button1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)

Label1.Text = Now.ToLongTimeString

UpdatePanel1.Update()

EndSubProtectedSub chk_CheckedChanged(ByVal senderAs System.Object,ByVal eAs System.EventArgs)'Never fires when checkbox is clicked unless autopostback=true.

Label1.Text = Now.ToLongTimeString

UpdatePanel1.Update()

EndSub

End

Class

yes, this is the correct behavior...
what it does is send a request to the server as soon as the checkbox status is changed.

So you're doing good :)

Great. Thanks for the confirmation, Peter.

Brent

No comments:

Post a Comment