admin管理员组

文章数量:1345011

I have the following source in 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:

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. However, when the javascript function ExtendPanel(PanelNumber) is executed, the click event seems to be fired, but the function is not executed.

I have the following source in 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:

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. However, when the javascript function ExtendPanel(PanelNumber) is executed, the click event seems to be fired, but the function is not executed.

Share Improve this question edited Jun 22, 2013 at 11:11 nmat 7,5916 gold badges31 silver badges43 bronze badges asked Jun 22, 2013 at 11:08 matchboxmatchbox 211 gold badge1 silver badge2 bronze badges 2
  • 1 fireEvent doesn't work in IE9 or greater. Why not just click? document.getElementById('<%=hidButton.ClientID%>').click(); – nmat Commented Jun 22, 2013 at 11:14
  • I have tried this. It still does not execute the click event. – matchbox Commented Jun 22, 2013 at 11:20
Add a ment  | 

4 Answers 4

Reset to default 4

Replace this

document.getElementById('<%=hidButton.ClientID%>').fireEvent("onclick");

with

__doPostBack('hidButton','OnClick');

try this

document.getElementById('<%=hidButton.ClientID%>').click();

Try this one below

$('#<%=hidButton.ClientID%>').click();

I got the same issues and resolved to put

OnClientClick="javascript:return true;"

本文标签: aspnetCalling the buttonclick() event from javascript doesn39t fireStack Overflow