在Javascript中查找asp:button和asp:textbox [英] Finding an asp:button and asp:textbox in Javascript

查看:295
本文介绍了在Javascript中查找asp:button和asp:textbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是得到一个asp:按钮来点击。





 < loginview> 
< asp:login1>
< logintemplate>
// asp:textbox和asp:button位于这里。
< / loginview>
< / asp:login>
< / logintemplate>

那么如何让javascript指向那个位置,以便我可以操作它。例如,点击按钮。

解决方案

首先,您需要弄清楚正在使用哪个模板,因为您可以只有访问活动的一个。 (匿名或登录)。一旦你这样做,在LoginView上使用FindControl方法找到你需要引用的元素的ClientID。



例如:

 < form runat =server> 
< asp:LoginView runat =serverID =LoginView>
< AnonymousTemplate>
< asp:Button ID =ASPButtonText =Buttonrunat =server/>
< / AnonymousTemplate>
< / asp:LoginView>
< / form>

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


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.

解决方案

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>

这篇关于在Javascript中查找asp:button和asp:textbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆