开发者

Finding an asp:button and asp:textbox in Javascript

What I'm trying to do is get an asp:button to click. The only problem is that it is within a few tags.

Example:

<loginview>
     <asp:login1>
          <logintemplate>
              //asp:textbox and asp:but开发者_如何学Cton are located here.
          </loginview>
     </asp:login>
</logintemplate>

So how would I get javascript to point to that location so that I can manipulate it. For example, get the button to click.


First, you need to figure out which template is being used, since you can only access the active one. (Anonymous or LoggedIn). Once you do that, use the FindControl method on the LoginView to find the ClientID of the element you need to reference.

For example:

<form runat="server">
  <asp:LoginView runat="server" ID="LoginView">
    <AnonymousTemplate>
      <asp:Button ID="ASPButton" Text="Button" runat="server" />
    </AnonymousTemplate>
  </asp:LoginView>
</form>

<script type="text/javascript">
 var el = document.getElementById('<%= LoginView.FindControl("ASPButton").ClientID %>');
</script>


Check out the jQuery framework: you can find controls by ID, and then call methods/properties on those controls.

http://jquery.com/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜