I need to send the actual control id that .NET generates for an U开发者_运维技巧pdatePanel's div to a javascript function. How do I rewrite the ScriptAction line below to accomplish this?
<asp:UpdatePanel ID="update1" runat="server" UpdateMode="Conditional">
...
</asp:UpdatePanel>
<cc1:UpdatePanelAnimationExtender runat="server" TargetControlID="update1">
<Animations>
<OnUpdating>
<Parallel duration="0">
<ScriptAction Script="doSomething(**update1's ID**);" />
</Parallel>
</OnUpdating>
...
</Animations>
</cc1:UpdatePanelAnimationExtender>
EDIT:
I would like to have update1.UniqueId
be placed in doSomething
's parameters.
EDIT:
The following fails:
<ScriptAction Script="alert('<%= update1.ClientID %>');" />
With
Exception type: System.Web.HttpParseException
Exception message: The 'Animations' property of 'cc1:UpdatePanelAnimationExtender' does not allow child objects.
Have you tried to use its ClientID?
Script="doSomething('<%= update1.ClientID %>');"
According to your updated question: add this ClientID as a javascript variable at the top of the page. Then you can access it from your js-function.
Something like this:
<script type="text/javascript"> var update1ClientID = '<%= update1.ClientID %>';</script>
and then:
Script="doSomething('' + update1ClientID );"
If this also doesn't work, try to use the same approach but from Codebehind(Page_Load)
ScriptManager.GetCurrent(Me.Page).RegisterClientScriptBlock(Me, Me.GetType, "update1ClientID", "var update1ClientID='" & Me.update1.ClientID & "';", True)
<ScriptAction Script="doSomething('<%=update1.ClientID %>');" />
** Edit *
To add to Tim's solution, if you have more than one custom control per page, iterate through the page controls and add a register script for each control that is of the type of your custom control.
精彩评论