我的网络控件上有以下按钮,
<asp:Button runat="server" ID="btnSave" Text="Save" onclick="btnSave_Click" OnClientClick="myShowWaitScreenWithNoClose('Processing...', 'Saving survey.Please wait it may take minutes..');" CssClass="buttons" Height="46px" Width="212px" Visible="false" />
我正在尝试使用隐藏代码中的 JavaScript 单击此按钮。就像,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "scr", "setTimeout(function(){document.getElementById('btnSave').click(); return false;}, 180000);", true);
}
}
但它抛出一个错误Error: TypeError: document.getElementById(...) is null
最佳答案
它会抛出此错误,因为您声明的 ID 与呈现的 ID 不同。
<asp:Button runat="server" ID="btnSave" clientIdMode="static">
添加 clientIdMode="static"
属性,以便您的 ID 将完全按照您声明的方式呈现。
关于c# - 从 javascript 调用 ASP 生成的按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15503657/