views:

31

answers:

2

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:button 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.

A: 

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

http://jquery.com/

Jaymz
+1  A: 

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>
Brandon
Thank you. I'll try this out.
BioXhazard