使用 jquery asp.net 在 ContentTemplate 中查找控件
我正在使用 jquery 查找 ContentTemplate 内的文本框控件。我不断收到错误:
名称“txtUserName”在当前上下文中不存在
这是我的 javascript:
function ShowAvailability() {
var myvar = $('#<%=txtUserName.ClientID %>').text();
$.ajax({
type: "POST",
url: "Register.aspx/CheckUserName",
data: '{userName: "' + $(myvar)[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
}
});
这是我的标记:
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="False" OnCreatedUser="RegisterUser_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<div class="accountInfo">
<fieldset class="register">
<div>
UserName :
<asp:TextBox ID="txtUserName" runat="server" onkeyup="ShowAvailability()"></asp:TextBox>
<input id="btnCheck" type="button" value="Show Availability" onclick="ShowAvailability()" />
<br />
<span id="mesg"></span>
</div>
请帮忙。我似乎无法在任何地方找到解决方案。谢谢!
I am using jquery to find a textbox control which is inside a ContentTemplate. I keep getting the error:
The name 'txtUserName' does not exist in the current context
This is my javascript:
function ShowAvailability() {
var myvar = $('#<%=txtUserName.ClientID %>').text();
$.ajax({
type: "POST",
url: "Register.aspx/CheckUserName",
data: '{userName: "' + $(myvar)[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
}
});
And this is my markup:
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="False" OnCreatedUser="RegisterUser_CreatedUser">
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<div class="accountInfo">
<fieldset class="register">
<div>
UserName :
<asp:TextBox ID="txtUserName" runat="server" onkeyup="ShowAvailability()"></asp:TextBox>
<input id="btnCheck" type="button" value="Show Availability" onclick="ShowAvailability()" />
<br />
<span id="mesg"></span>
</div>
Please help. I can't seem to find the solution anywhere. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要尝试选择它,而是让它作为参数出现:
然后在标记中使用 jquery $(this) 让文本框将其自身的引用发送给函数:
Instead of trying to select it, let it come to you as a parameter:
Then in the markup use the jquery $(this) to have the text box send a reference of itself to the function: