What is the proper use of Jquery's $get to retrieve a control
How might I reference a control in JQuery so that i开发者_开发技巧t wont throw an error if the control doesnt exist?
ie: this at the moment throws server error in asp.net
if ($get('<%= Panel1.ClientID %>') != null) { <-- Fails with "The name 'Panel1' does not exist in the current context"
$get('<%= Panel1.ClientID %>').scrollTop = yPos;
}
which is present in a master page, but for certain content pages will exist, in those cases I have code to reset the scroll position.
Thanks
This is a server-side issue, not jQuery. Panel1.ClientID
is evaluated on the server-side while the page is being generated.
Also, the jQuery you need is $('#<%= Panel1.ClientID %>')
You could assign this panel some CSS class and then use a CSS selector in jQuery:
$('.someClassNameOfThePanel').scrollTop(yPos);
and on the server the Panel could look like this:
<asp:Panel ID="Panel1" runat="server" CssClass="someClassNameOfThePanel">
...
</asp:Panel>
精彩评论