0

I need to send the actual control id that .NET generates for an UpdatePanel'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.
Tim Santeford
  • 27,385
  • 16
  • 74
  • 101

2 Answers2

1
<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.

TheGeekYouNeed
  • 7,509
  • 2
  • 26
  • 43
1

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)
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • Yeah this would work but unfortunately for me the updatepanel is inside a custom control and there could be more than one per page. I will accept your answer however because it would work otherwise. – Tim Santeford Jan 26 '11 at 22:42
  • ^^: I don't know what your `doSomething`-function does, but can't you register that function via RegisterClientScriptBlock and add the UpdatePanel's ClientID inside of that function with `'<%= update1.ClientID %>'`? On this way you wouldn't need to pass the id as parameter. – Tim Schmelter Jan 26 '11 at 23:13