[英]Calling the button.click() event from javascript doesn't fire
I have the following source in aspx: 我在aspx中有以下来源:
<div>
<asp:HiddenField ID="hidValue" runat="server" />
<asp:Button runat="server" ID="hidButton" OnClick="hidButton_Click" />
<script type="text/javascript">
function ExtendPanel(PanelNumber) {
var hidValue = document.getElementById('<%=hidValue.ClientID %>');
hidValue.value = PanelNumber;
document.getElementById('<%=hidButton.ClientID%>').fireEvent("onclick");
}
</script>
</div>
In my code behind, I have the following C# function declared: 在后面的代码中,我声明了以下C#函数:
protected void hidButton_Click(object sender, EventArgs e)
{
int PanelNumber = int.Parse(hidValue.Value);
... do something with PanelNumber ...
}
When I click on the button using the mouse, "hidButton_Click" function is normally executed. 当我使用鼠标单击按钮时,通常会执行“ hidButton_Click”功能。 However, when the javascript function ExtendPanel(PanelNumber) is executed, the click event seems to be fired, but the function is not executed.
但是,执行javascript函数ExtendPanel(PanelNumber)时,似乎触发了click事件,但未执行该函数。
Replace this 取代这个
document.getElementById('<%=hidButton.ClientID%>').fireEvent("onclick");
with 同
__doPostBack('hidButton','OnClick');
尝试这个
document.getElementById('<%=hidButton.ClientID%>').click();
在下面试试这个
$('#<%=hidButton.ClientID%>').click();
I got the same issues and resolved to put 我遇到了同样的问题,并决定放
OnClientClick="javascript:return true;" OnClientClick =“ javascript:return true;”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.