gpt4 book ai didi

ASP.NET 文本框 AutoPostBack 未触发

转载 作者:行者123 更新时间:2023-12-04 18:11:23 25 4
gpt4 key购买 nike

搜索后,我发现了许多建议,但没有一个能解决问题。

<asp:TextBox runat="server" ID="uid" AutoPostBack="True" Text=""></asp:TextBox>

在属性窗口中,TextBox ( Suggested here) 的 EnableViewState = True。我在 TextBox 中输入一个新值,然后按 Tab 键。 if(IsPostBack...) 处的断点也没有发生任何事情。

代码背后:
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack && uid.Text != "" && pw.Text == "")
{
Do stuff
}
}

更新:我尝试过的其他文本框设置:
<asp:TextBox runat="server" ID="uid" Text="" AutoPostBack="True" OnTextChanged="UidTextChanged"></asp:TextBox>

protected void UidTextChanged(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('it works');", true);
}


 <asp:TextBox runat="server" ID="uid" AutoPostBack="True" Text="" onblur="__doPostBack('','');" OnTextChanged="UidTextChanged"></asp:TextBox>


 <asp:TextBox runat="server" ID="uid" AutoPostBack="True" Text="" onblur="__doPostBack('','');"></asp:TextBox>

每当 AutoPostBack 设置为 true 时,我都会在浏览器控制台中收到以下错误:
"Uncaught TypeError: Property 'submit' of object #<HTMLFormElement> is not a function
__doPostBack
(anonymous function)"

当我设置了 onblur 属性时,我收到了完全相同的错误,除了它说的是 onblur 而不是匿名函数。

最佳答案

您可以为它添加一个 javascript 事件到 onblur 中。 onblur='__doPostBack('','');'
这将导致您的文本框一旦被标记出来就会导致回发。

编辑:它应该是“不是”<asp:TextBox ID="TextBox1" runat="server" onblur="__doPostBack('','');" />刚刚尝试过,它有效。尝试删除AutoPostBack="True"
编辑2:基于您的pastebin ....<asp:Button runat="server" UseSubmitBehavior="True" ID="submit" Text="Save"
onclick="SubmitClick"/>
您不能拥有“提交”的 ID。将其更改为“btnSubmit”,Javascript 解决方案将起作用,我敢打赌 Auopostback 解决方案也将起作用。
http://www.xpertdeveloper.com/2012/05/property-submit-of-object-is-not-a-function/将解释问题。

关于ASP.NET 文本框 AutoPostBack 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com