2

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.

2
  • 1
    fireEvent doesn't work in IE9 or greater. Why not just click? document.getElementById('<%=hidButton.ClientID%>').click(); Commented Jun 22, 2013 at 11:14
  • I have tried this. It still does not execute the click event. Commented Jun 22, 2013 at 11:20

4 Answers 4

4

Replace this

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

with

__doPostBack('hidButton','OnClick');
Sign up to request clarification or add additional context in comments.

3 Comments

Nope, that doesn't do the trick. I am using the same principle on other pages in my project as well, and they work perfectly.
you can also use this code.. var clickButton = document.getElementById("<%= hidButton.ClientID %>"); clickButton.click();
then u can submit the form using javascript and check the condition in page load if match then call the required function. code for submit the form is - document.getElementById('form').submit();
1

try this

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

Comments

0

Try this one below

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

Comments

0

I got the same issues and resolved to put

OnClientClick="javascript:return true;"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.