views:

405

answers:

3

Good Day,

We have migrated our web application to ASP.NET 2.0 from ASP.NET 1.1.

We have a page that contains a couple of textboxes with their respective Validators.

On .NET 1.1, when a textbox contains an INVALID value, clicking on the "submit" button, will not produce a postback (E.G. Nothing will happen).

However, when we migrated to .NET 2.0, even if there is an INVALID value, the postback will still happen. (E.G. Pressing the "submit" button will perform a postback).

Is there an issue with validation when migrating from 1.1 to 2.0?

Additional Infos: The "submit" button is an input button:

<input type="button">

Using an <asp:button> in place of the <input> button will work and will fix the problem. However, the <input type="button"> has the capability to call a javascript that will produce a "Wait... Loading" label overlay on the page. Using the asp:button, the "Wait... Loading" overlay javascript will NOT be invoked.

EDIT: Real problem and solution.

Anyway, the real problem is that the on-click validation javascript was broken during migration.

The original and working script is:

<input language="javascript" onclick="{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')} " name="m_bt_Save" id="m_bt_Save" type="button" value="Save" width="80px" height="24px" />

But ASP.NET 2.0 changed it to:

<input onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(''); __doPostBack('m_bt_Save','')" name="m_bt_Save" type="button" id="m_bt_Save" value="Save" width="80px" height="24px" />

So the my solution was, change the INPUT button to an ASP:button, then add the attribute doing page load with the correct ASP.NET 1.1 javascript validation like so:

m_bt_Save.Attributes.Add("OnClick", "if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) __doPostBack('m_bt_Save','')");
+1  A: 

One thing you can do, is you can just add your JS that you need to the button.

Button1.Attributes.Add("OnClick", "do my js stuff here");

That will allow you to have the exact same functionality as the input, and it makes it work.

Otherwise, my guess is that you will need to modify the way the input button submits to call the validate page method before it does the from submit.

Mitchel Sellers
I agree, if you switch to an <asp:Button and add the javascript attribute to the button dynamically on the server side your problem should go away.
wweicker
Hi, thanks for the quick response. Does the "do my js stuff here" be executed *immediately* OnClick? Like the behavior of the input button?
Ian
@ian - yes it is!
Mitchel Sellers
This *helped* in solving my problem. Check my edits on the question for the real problem and solution.
Ian
A: 

This happened in our upgrade as well. I think we narrowed it down to a problem with the WebUIValidation.js file. I think re-installing it was the final fix for us.

Coov