views:

104

answers:

3

One of our ASP.NET WebForms 3.5 pages just suddenly decided not to render the __doPostBack() javascript method, along with the supporting <hidden> fields, anymore.

Everything else seems OK on the page - the only thing I changed was that I removed a postback handler on a SelectList control, and changed AutoPostback from True to False on the same control. There are still several other (unchanged) elements on the page that have postback handlers.

I'm also using jQuery validation on the page, but it was working like a charm before, and I haven't changed anything in the javascripts. And yes, I've seen this question, but that solution does not apply to me - we're not using any caching at all at the moment.

UPDATE:
It seems that ASP.NET is deciding my client scripts aren't needed, since no controls are depending on postback. However, I have a button control for submitting, which has an event handler on the server side, and that event handler is never called - I suspect this is because the button is allowed to be just a regular <input type="submit"> and submitting the form in standard HTTP ways, instead of with the ASP.NET __doPostBack script.

This is my control (visible is set to True in code-behind):

<asp:Button ID="SaveNewButton" runat="server" CssClass="inputbutton"
    Visible="false" OnClick="SaveNewButton_Click" />

And this is the handler method in code-behind:

Protected Sub SaveNewButton_Click(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles SaveNewButton.Click

How do I force ASP.NET to render the client scripts for postbacks, so my event handler is called?

A: 

Does your <form> tag still have the runat="server" attribute?

Neil Moss
Yes, it does, as do all the other server controls on the page.
Tomas Lycken
+1  A: 

IIRC, ASP.NET only renders the __doPostback() javascript when it thinks it is needed, that is, if there are controls on the page that need to trigger a postback while the HTML controls they render do not natively do so. A button can trigger a postback through a regular non-scripted submit, so your dropdown might have been the only control needing the scripted postback. When you changed its autopostback property to false, you probably removed the need for __doPostback, so ASP.NET doesn't render it anymore.

tdammers
This seems plausible. Is there any way to force ASP.NET to render the scripts?
Tomas Lycken
A: 

The problem was, as tdammers noted, that ASP.NET only renders the __doPostback() javascript when it thinks it's needed, and in this case it didn't think so. The solution was given to me in a thread at forums.asp.net and was as simple as this:

Set UseSubmitBehavior="False" on the button that should submit with __doPostBack() and not using the browser's default submit behavior.

Tomas Lycken