Reply to comment
Fix for Firefox click() event issue
Firefox does not support the javascript click() event on a hyperlink. So doing something like:
<asp:LinkButton ID="lnkMyButton" runat="server">My Button To Click</asp:LinkButton>
<a href="#" onclick="document.getElementById('lnkMyButton').click();">Click this to click the other link!</a>
This will work correctly in Internet Explorer but nothing will happen when you execute this javascript in FireFox.
This is because the javascript line in Firefox has the click() event and Firefox does not understand this event for hyperlinks (which is what an ASP.NET LinkButton control is rendered as on page load):
document.getElementById('lnkMyButton').click();
Workaround 1:
Instead of using a LinkButton control, use a Button control instead. Firefox does support the click() event for input type=button HTML controls. So you could change the code to this:
<asp:Button ID="btnMyButton" runat="server" />
<a href="#" onclick="document.getElementById('btnMyButton').click();">Click this to click the other button!</a>
Workaround 2:
If you can’t change the element to a Button control instead of a LinkButton, you can simulate the postback event by calling the method that .NET calls in the background when you click on the LinkButton control directly. This event is called __doPostBack() and takes the ID name of the control that you want to cause a postback. So you could change the code to this:
<asp:LinkButton ID="lnkMyButton" runat="server">My Button To Click</asp:LinkButton>
<a href="#" onclick="__doPostBack('lnkMyButton', '');">Click this to click the other link!</a>
The nice thing about this one is that even if this is in an ASP.NET AJAX UpdatePanel, it will still do the asynchronous postbacks correctly and post the link button.
Reply
Popular Articles
Last viewed:
- C# Generate Password Hash with Salt
- C# Free Component to Generate PDF - Convert HTML to PDF
- Clustered Index vs. Non-Clustered Index in SQL Server
- Getting Started with Microsoft Chart Controls for ASP.NET 3.5
- GridView ObjectDataSource LINQ Paging and Sorting
- Data Access Layer using SqlDataReader and C#

Recent comments
14 hours 32 min ago
1 day 14 hours ago
3 days 15 hours ago
4 days 4 hours ago
4 days 15 hours ago
4 days 21 hours ago
5 days 1 hour ago
1 week 22 hours ago
1 week 1 day ago
1 week 4 days ago