I am currently working on a .NET 4 web page that incorporates a User Control featuring the following elements:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:LinkButton ID="btnExpand" runat="server" Text="Expand..." ClientIDMode="AutoID"
OnClick="btnExpand_Click"></asp:LinkButton>
<asp:Label ID="btnDummy" runat="server"></asp:Label>
<asp:Panel ID="pnlMyPanel" runat="server">
<p>content</p>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="cpeMyPanel" runat="server"
TargetControlID="pnlMyPanel" Collapsed="True" ExpandControlID="btnDummy"
CollapseControlID="btnDummy" BehaviorID="cpe">
</ajaxToolkit:CollapsiblePanelExtender>
Upon clicking the "Expand" button, the code to execute is as follows:
protected void btnAddComment_Click(object sender, EventArgs e)
{
string script = "var cpeMyPanel = $find('" + cpeMyPanel.BehaviorID + "');\r\n" +
"if (cpeMyPanel != null)\r\n" +
" cpeMyPanel.expandPanel();\r\n" +
"else\r\n" +
" alert(cpeMyPanel is null');";
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"Expand", script, true);
}
Currently, upon executing the script in the browser, I receive an alert stating that $find() always returns null. My ultimate objective is to trigger some server-side code when the user clicks the button, before expanding the panel.
Any insights into what might be missing from my implementation? Alternatively, is there a more effective approach to achieve this functionality?
Thank you for your assistance,
Dan