Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将textbox值传递给javascript函数_Javascript_Jquery_Asp.net - Fatal编程技术网

将textbox值传递给javascript函数

将textbox值传递给javascript函数,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我的asp.net页面中有一个Js函数,如下所示: function LoginPopup(username,password) { alert(username); alert(password); username = username.val(); password = password.val(); } <asp:Button ID="btnLogin" runat="server" UseSubm

我的asp.net页面中有一个Js函数,如下所示:

 function LoginPopup(username,password) {     

        alert(username);
        alert(password);

        username = username.val();
        password = password.val();

}
<asp:Button ID="btnLogin" runat="server" UseSubmitBehavior="false" OnClientClick="LoginPopup('<%# UsernameTextBox.ClientID %>', '<%# PasswordTextBox.ClientID %>');  return false;"
                                    CssClass="login-button" Text="<%$ Resources: HRGELoggedOutMaster, Login %>">
                                </asp:Button>
我是这样使用它的:

 function LoginPopup(username,password) {     

        alert(username);
        alert(password);

        username = username.val();
        password = password.val();

}
<asp:Button ID="btnLogin" runat="server" UseSubmitBehavior="false" OnClientClick="LoginPopup('<%# UsernameTextBox.ClientID %>', '<%# PasswordTextBox.ClientID %>');  return false;"
                                    CssClass="login-button" Text="<%$ Resources: HRGELoggedOutMaster, Login %>">
                                </asp:Button>

但是我看到LoginPopup得到的是“”,而不是UsernameTextBox的客户端Id。我想将UsernameTextBox和passwordtexbox的值传递给LoginPopup


请建议。

您能试试这个,
document.getElementById()


更正了
ClientID
语法:

<asp:Button ID="btnLogin" runat="server" UseSubmitBehavior="false" OnClientClick="LoginPopup('<%=UsernameTextBox.ClientID %>', '<%=PasswordTextBox.ClientID %>');  return false;"
                                CssClass="login-button" Text="<%$ Resources: HRGELoggedOutMaster, Login %>">
                            </asp:Button>

如果您使用Gridview,请尝试此示例方法

<ItemTemplate>
              <asp:LinkButton ID="lnkgettext" runat="server" OnClientClick='<%# String.Format("return callme({0})", (((GridViewRow)Container).FindControl("txtName") as TextBox).ClientID) %>'
                        Text="Gettextboxvalue"></asp:LinkButton>
</ItemTemplate>

如何调用LoginPopup?OnClientClick=“LoginPopup(“”,”);return false;”它显示以下html:@DotnetSparrow这是正确的语法。您知道,为了工作,必须使用
runat=“Server”
将其放在一个且唯一的表单中?是的,在这种情况下,只有一个表单使用runat Server如果您查看浏览器中按钮的源代码,有clientId,或
?Asp.Net可能还有其他问题。@DotnetSparrow如果您使用Asp.Net 4+,您可以使用以下命令要求它不要更改id:
clientdmode=“Static”
。有两个控件具有用户名文本框名称,一个在主页面上,另一个在主页面上。这些字段是否在gridview内部使用?不,它不在gridview中
<ItemTemplate>
              <asp:LinkButton ID="lnkgettext" runat="server" OnClientClick='<%# String.Format("return callme({0})", (((GridViewRow)Container).FindControl("txtName") as TextBox).ClientID) %>'
                        Text="Gettextboxvalue"></asp:LinkButton>
</ItemTemplate>
function callme(cntrl) {
            alert(cntrl.id);
            alert(cntrl.value);
            return false;
}