In this article I will explain with an example, how to resolve the following
JavaScript error:
__doPostBack is not defined in ASP.Net.
Error
Error occurs when a person tries to use the
__doPostBack JavaScript function and the Web Page does not contain any control which requires it and hence the following
JavaScript error is raised.
What is __doPostBack?
1. The
__doPostBack is an ASP.Net in-built
JavaScript function which is used to submit (PostBack) the Form to the server for controls other than
Submit Button.
2. It is added to the Web Page automatically only when it is required i.e. when Controls other than Submit Button such as LinkButton, ImageButton, etc. are used.
3. A normal HyperLink or Image gets converted into a
Submit Button by calling
__doPostBack JavaScript function.
Solution
The solution to the problem is very simple. Just add a dummy LinkButton to the page and hide it by setting CSS style as display:none as shown below.
<asp:LinkButton ID="lnkButton" runat="server" Style="display: none"></asp:LinkButton>
Note: Here Visible="false" attribute will remove the control from the Web Page and hence the
__doPostBack JavaScript function will not be rendered
Downloads