Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ScriptManager RegisterAsyncPostBackControl doesn't seem to work...

Status
Not open for further replies.

blondebier

Programmer
Jun 19, 2003
142
GB
Hi Guys,

I have a master page in my solution with a script manager that should catch the click event of a button on it.

i.e. ScriptManager.GetCurrent(Me.Page).RegisterAsyncPostBackControl(Me.TestButton)

I then have the code for my test button:

Protected Sub TestButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TestButton.Click
Try
If Not WebFormContent.FindControl("UpdatePanel") Is Nothing Then
Dim up As UpdatePanel
up = WebFormContent.FindControl("UpdatePanel")
up.Update()
End If

Catch ex As Exception
' Do nothing
End Try
End Sub

My ContentPage has an update panel on it that I want to update without posting back.

<asp:Content ID="Content3" ContentPlaceHolderID="WebFormContent" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy" runat="server"></asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Test" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

I added a ScriptManagerProxy for good measure as they seem to be required...

This does not work though. Every time I click on my test button it does a full post back.

Any ideas?

Cheers,

Francis

 
1. you should register the button click event with the update panel not the script manager. the update panel takes care of any inner workings with the script manager.
2. you don't need a script manager proxy unless your referencing additional scripts not associated with the script manager.
3. you don't need to call the updatepanel.update.
4. you shouldn't need to use the FindControl("Mypanel") within the WebFormContent. simply reference Me.MyPanel.Update(); (which you don't need in this case).
5. when using FindControl you need to cast the control to a specific type. CType(MyContent.FindControl("MyPanel"), UpdatePanel.GetType())
6. visit and view some of the online tutorials. they average 10 minutes and get you up and running quickly.

your code should should look something like this.
Code:
//masterpage.master
<asp:ScriptManger runat="server" ... PartialRendering="true" />
<asp:Content id="MyContent" placeholder="Content1" ... />


//aspx
<asp:ContentPlaceholder id="ThisContent" placeholder="Content1" ...>
   <asp:UpdatePanel ...>
       <Content>
           //your controls here
       <Content>
       <Triggers>
           <asp:AsyncPostBackTrigger ControlId="MyButton" Event="Click" />
       </Triggers>
   <asp:UpdatePanel>
   <asp:Button id="MyButton" runat="server" ... />
</asp:ContentPlaceholder />


//aspx.vb
protected sub MyButton_Click(...)
   //process page (no need to reference update panel)
end sub

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks for the reply.

My problem was the web.config. I was trying to add AJAX to an existing web application. When you create an AJAXEnabledWebApplication it adds some other entries not normally found in a standard web.config file.

Frustrating to the max!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top