user8002547
user8002547

Reputation:

Html Button click is not working on Firefox

On my webpage I have a html button , It works perfectly on chrome and I have no idea why its not working on Firefox . please tell my why its not working..

Design

<div class="col-md-3">
     <button id="Button1" class="btn btn-green btn-block" onserverclick="SaveIt" runat="server">
      Save <i class="fa fa-arrow-circle-right"></i>
     </button>
 </div>

C# Function

protected void SaveIt(object sender, EventArgs e)
{
    //operations
}

How to solve this browser compatibility issue ??

Upvotes: 2

Views: 747

Answers (3)

VDWWD
VDWWD

Reputation: 35544

Unlike an asp:button, the click is handled with javascript (just like a LinkButton). In html the button becomes something like this:

<button onclick="__doPostBack('ctl00$mainContentPane$Button1','')" id="mainContentPane_Button2" class="btn btn-green btn-block">

So if it does not work it could be a javascript error present in Firefox but not Chrome. Here some tips

  • Test it with a LinkButton
  • Check the browser console for javascript errors
  • Do you have browser-specific scripts somewhere, if so remove them for testing

Upvotes: 0

Sean T
Sean T

Reputation: 2504

You need to change your button control to an asp button. It should work then. Like this...

<asp:Button ID="Button1" runat="server" OnClick="SaveIt()" Text="Save" /> 

Upvotes: 1

Bozhidar Stoyneff
Bozhidar Stoyneff

Reputation: 3634

In ASP.NET WebForms everything that should interact with the server - as in this case, where you handle the click ON the server - needs to be placed within a form tag. It is not clear from your post, but I'm assuming you didn't create one in your master page ...

Upvotes: 0

Related Questions