__doPostBack is not defined

2019-01-18 01:46发布

Im getting that error when try to call a __doPostBack on one of my pages, every page that i have in the project use __doPostBack function but in this particular page im getting that Javascript error.

i was looking in the internet and the only thing i read is that this error happends when i have a unclose tag but i review the site and its ok.

Error: __doPostBack is not defined Source File: htt://localhost:99/ProjectName/Disable.aspx Line: 1

25条回答
干净又极端
2楼-- · 2019-01-18 02:44

I was getting this because my script was inside an Iframe that was being "disposed" (it was a Telerik "window" that was closed). The code defining _dopostback() inside my iframe was gone, but the code calling _dopostback() inside my iframe was still hanging around. Love that JavaScript!

查看更多
欢心
3楼-- · 2019-01-18 02:46

Wrapping my server side controls in a form element with runat="server" attribute worked for me. According to asp environment there should be only one form element with runat="server" attribute in it otherwise some serious issue may happen.

<form runat="server" id="form1">
   <!-- Server side controls go here -->
</form>
查看更多
可以哭但决不认输i
4楼-- · 2019-01-18 02:48

i used this method in my script that included to asp.net form:

main form id sample:
<script src="myscript" />

<form id="frmPost" runat="server">
</form>

// myscript.js in java script function
mypostboack: function () {
$('#frmPost').context.forms[0].submit()
}
查看更多
小情绪 Triste *
5楼-- · 2019-01-18 02:48

For me it was the following was missing from the page:

<form runat="server">
</form>
查看更多
何必那么认真
6楼-- · 2019-01-18 02:49

Here's why this was happening to me: I accidentally forgot that script tags must always have closing tags:

<script src="/Scripts/appLogic/Regions.js" />

I corrected the script tag:

<script src="/Scripts/appLogic/Regions.js" type="text/javascript" ></script>

and sanity returned.

查看更多
Emotional °昔
7楼-- · 2019-01-18 02:49

__doPostBack Works guys

Write this code in Page Load

ClientScript.GetPostBackEventReference(this, "");

查看更多
登录 后发表回答