matchbox
matchbox

Reputation: 21

Calling the button.click() event from javascript doesn't fire

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.

Upvotes: 2

Views: 27506

Answers (4)

Eugine Manuel
Eugine Manuel

Reputation: 1

I got the same issues and resolved to put

OnClientClick="javascript:return true;"

Upvotes: 0

Arif YILMAZ
Arif YILMAZ

Reputation: 5866

Try this one below

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

Upvotes: 0

sangram parmar
sangram parmar

Reputation: 8726

try this

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

Upvotes: 1

Raghubar
Raghubar

Reputation: 2788

Replace this

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

with

__doPostBack('hidButton','OnClick');

Upvotes: 4

Related Questions