DoPostBack sometimes isn't in HTML

K

Kevin

Hey guys,

I really can't narrow this one down but I hope someone can help. The
problem is intermittent and debugging is almost impossible. Nothing
strange in the IIS logs. Basically, sometimes the __doPostBack JS
method isn't injected into the HTML. Here are 2 HTML snippets of the
two different outputs of the same file. First one is the way it should
look:

<form name="aspnetForm" method="post" action="home.aspx?id=8338"
id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET"
value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

AND here is a snippet, calling exactly the same file... and the
__doPostBack isn't rendered.

<form name="aspnetForm" method="post" action="/home.aspx?id=8338"
id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]/>

HERE is the C# code for the form that is supposed to trigger the
__doPostBack to be injected:

< %@ control language="C#" autoeventwireup="true"
inherits="Controls_HeaderSearch" CodeFile="HeaderSearch.ascx.cs" % >
< asp:TextBox ID="searchBox" runat="server" CssClass="searchbox"
MaxLength="128" Text="< %$ Resources:UI, Search % >" / >
< asp:LinkButton ID="btnSearch" runat="server"
CssClass="searchButton" OnClick="btnSearch_Click"
CausesValidation="false" / >


What could possibly be causing the __doPostBack to not show? It's
almost like .Net is just getting lazy on some requests. But we all
know that's not possible... or is it? :-b

Other possible factors (but don't think these would cause it)
We are running Ektron, but Ektron doesn't control whether the
__doPostBack appears, our C# code does.
Out content is cached over the Akamai network, but Akamai
shouldn't be stripping out content.

Anyone have any ideas?

Thanks so much,
Kevin
 
M

miher

Hi,

AFAIK ASP.Net is clever enought to render the __doPostBack only when it is
needed. (So for example if You put a dropdown to an empty page, no
__doPostBack will be rendered, but if You turn AutoPostBack on, You will get
the function.) I think if You drop a scriptmanager to the page, You will get
the function for sure.

Hope You find this useful.
-Zsolt
 
G

George

__doPostBack only shows up when it needs to...

If for example you have a LinkButton then it will be there.
If you have regular button then the form is submitted the usual way via
<input type="submit"> and __doPostBack is not injected.

If you need to have it in HTML then you have 2 ways.
1. Simply dump empty link button on your form. You can even add
style="disply:none" to it.
2. use ClientScriptManager.GetPostBackEventReference



George


Kevin said:
Hey guys,

I really can't narrow this one down but I hope someone can help. The
problem is intermittent and debugging is almost impossible. Nothing
strange in the IIS logs. Basically, sometimes the __doPostBack JS
method isn't injected into the HTML. Here are 2 HTML snippets of the
two different outputs of the same file. First one is the way it should
look:

<form name="aspnetForm" method="post" action="home.aspx?id=8338"
id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET"
value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

AND here is a snippet, calling exactly the same file... and the
__doPostBack isn't rendered.

<form name="aspnetForm" method="post" action="/home.aspx?id=8338"
id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]/>

HERE is the C# code for the form that is supposed to trigger the
__doPostBack to be injected:

< %@ control language="C#" autoeventwireup="true"
inherits="Controls_HeaderSearch" CodeFile="HeaderSearch.ascx.cs" % >
< asp:TextBox ID="searchBox" runat="server" CssClass="searchbox"
MaxLength="128" Text="< %$ Resources:UI, Search % >" / >
< asp:LinkButton ID="btnSearch" runat="server"
CssClass="searchButton" OnClick="btnSearch_Click"
CausesValidation="false" / >


What could possibly be causing the __doPostBack to not show? It's
almost like .Net is just getting lazy on some requests. But we all
know that's not possible... or is it? :-b

Other possible factors (but don't think these would cause it)
We are running Ektron, but Ektron doesn't control whether the
__doPostBack appears, our C# code does.
Out content is cached over the Akamai network, but Akamai
shouldn't be stripping out content.

Anyone have any ideas?

Thanks so much,
Kevin
 
K

Kevin

Thanks George and Miher,

I've actually read about the GetPostBackEventReference in a few other
posts. But the issue is that _doPostBack DOES in fact show up... just
sometimes it doesn't. As far as I know, there aren't any differences
in the requests.

Got anything else up your sleeve?

Thanks,
Kevin
 
G

George

Very possible that you have a LinkButton wich is set Visible/Not Visible in
the code (see property Visible)

Hence you have __doPostBack shows up and then not shows up.

George.
 
K

Kevin

Yes, but it is always true, based on the web.config which hasn't
changed in months:

Visible = Boolean.Parse(ConfigurationManager.AppSettings
["HeaderSearchVisible"]);

The search box and button always show up. But when this problem
occurs, submitting the form causes a JS error since the doPostBack
function isn't there.

Any other ideas?
 
C

Cowboy \(Gregory A Beamer\)

I have never seen this personally. Is this only on dev, or also on
production?

One thing that happens routinely on dev, at least in certain situations, is
the ASP.NET temp files become corrupt. Very common with the Profile bits,
which has caused me to always use a custom Profile provider. Silverlight has
some similar tendencies during dev.

ONe way around the error is remove the page from the site and compile. Then
add back. If this does not solve the problem, remove, compile, create a new
page with the same name and copy over the code.

If that does not work, debug is the option, but I am not sure how you would
debug a "fail to create postback" situation. In fact, I would have to search
and see if there is a debug ASP.NET runtime available for "end user" use,
with end user = developer.


Kevin said:
Hey guys,

I really can't narrow this one down but I hope someone can help. The
problem is intermittent and debugging is almost impossible. Nothing
strange in the IIS logs. Basically, sometimes the __doPostBack JS
method isn't injected into the HTML. Here are 2 HTML snippets of the
two different outputs of the same file. First one is the way it should
look:

<form name="aspnetForm" method="post" action="home.aspx?id=8338"
id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET"
value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

AND here is a snippet, calling exactly the same file... and the
__doPostBack isn't rendered.

<form name="aspnetForm" method="post" action="/home.aspx?id=8338"
id="aspnetForm">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="[...blah blah...]/>

HERE is the C# code for the form that is supposed to trigger the
__doPostBack to be injected:

< %@ control language="C#" autoeventwireup="true"
inherits="Controls_HeaderSearch" CodeFile="HeaderSearch.ascx.cs" % >
< asp:TextBox ID="searchBox" runat="server" CssClass="searchbox"
MaxLength="128" Text="< %$ Resources:UI, Search % >" / >
< asp:LinkButton ID="btnSearch" runat="server"
CssClass="searchButton" OnClick="btnSearch_Click"
CausesValidation="false" / >


What could possibly be causing the __doPostBack to not show? It's
almost like .Net is just getting lazy on some requests. But we all
know that's not possible... or is it? :-b

Other possible factors (but don't think these would cause it)
We are running Ektron, but Ektron doesn't control whether the
__doPostBack appears, our C# code does.
Out content is cached over the Akamai network, but Akamai
shouldn't be stripping out content.

Anyone have any ideas?

Thanks so much,
Kevin
 
Joined
Nov 2, 2009
Messages
1
Reaction score
0
Hi - I am having this same issue and cant tract it down - has anyone found a solution or cause here?

The page should have this function created as it has items on it which require a post back, so its not a matter of adding something that requires a postback.. this happens randomly as far as im aware.. sometimes the pages work (have the function) and sometimes they dont. clearing the server cache or resetting the app pool seems to fix it..

any more ideas as to why?
 
Joined
Nov 25, 2008
Messages
4
Reaction score
0
Does your application use any CDN?

Does you App use any CDN?

ref a great article around this
dotnetlite * com /2010/06/21
/
loss-of-__dopostback-code-after-protecting-a-site-with-akamai/

Good Luck,
HydTechie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,056
Messages
2,570,446
Members
47,096
Latest member
noshit.sherlock

Latest Threads

Top