Problem
__doPostBack
is a
JavaScript function automatically added to
Submit the form resulting in a Post Back. This is added for the Web Controls having any Event which will cause a
Post Back.
In your case, you have don't have anything on the page, which would cause a
Post Back. So, this function is not added to the
Page, which shows the following Error on
Developer Console Window.
ReferenceError: __doPostBack is not defined
__doPostBack("GridView1", " ");
Solution
The easiest way I found is to add attribute
AutoPostBack="true"
to the
TextBox
. So, it will become...
<asp:TextBox ID="txt" onkeyup="fun();" runat="server" AutoPostBack="true"></asp:TextBox>
Now, you can see
__doPostBack
is added to the Page Script after it is rendered on Browser.
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
After this, lets type something on the
TextBox
, it will
Post Back, but throws
Exception...
Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true" /> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
To remove this, you can add
EnableEventValidation="false"
to the
Page Directive which is not recommended.
Refer -
Page.EnableEventValidation Property[
^]
Quote:
If you write client script that changes a control in the client at run time, you might have to use the RegisterForEventValidation[^] method in order to avoid false event validation errors.
Security Note
This feature reduces the risk of unauthorized or malicious postback requests and callbacks. It is strongly recommended that you do not disable event validation.
If you set
EnableEventValidation="false"
, then it would Post Back acoording to your requirements. But I would not suggest that.
Conclusion
Please reconsider the
Logic and think why you want to
Post Back explicitly. You can directly add Events to
GridView
directly or use
RegisterForEventValidation[
^] method.