Client Validation Javascript not rendering

G

Guest

Hi,
I have run into a very strange scenario. In developing an ASP.NET
application on framework version 1.1, I found that certain client-side
validation scripts were not being rendered. The reason we came up with for
this was because we had a PageBase base class for all our pages. This base
class takes the controls on the child page class and places them onto the
form being rendered. It seems that in this process, the rendering of the
validation calls gets lost. To overcome this problem I added code to add the
required client-side function call on the "onclick" event of the necessary
buttons as follows:

<input type="submit" name="btnSave" value="Save" onclick="btnClose.enabled =
'false';if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
language="javascript" id="btnSave" class="button" style="width:68px;" />

Can anybody tell me if the original problem was a bug in the framework, IIS5
etc.? Also, if it was a framework bug, why does it differ with the same
version on WinXP Pro and Win2003 Server?

Any light on this subject will be greatly appreciated.

Fourge
btnSubmit.Attributes.Add("onclick","btnClose.enabled = 'false';if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ");

After adding this, it worked great in our development and test environment.
Our development is done on Windows XP Pro with IIS5 and our testing on
Windows 2000 Server with IIS5. Both environments running .NET Framework 1.1.

One of the deployments we did was into the Windows 2003 Server environment.
Once th application was running in that environment, we found that the
validation function calls above were now being added and so we were getting
the javascript calls twice in the rendered html page as follows:
 
P

Peter Blum

While there is a bug in client-side validation in ASP.NET 1.1 SP1, I don't
think it is involved here. That bug prevents the button click from ever
submitting the page. See
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=739537

If the button is not generating its onclick event code, there are two
possible reasons:
1. CausesValidation is false on the button.
2. The Page.Validators collection has no validators (or perhaps just
"active" validators where their Visible property is true.)

I don't know how your code moves controls around and wonder if it ends up
clobbering the Page.Validators collection.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
S

Steven Cheng[MSFT]

Hi Fourge,

I'm also a bit interested in how your base pages adding those validation
controls. As far as I knew, the validation control will regsiter the
clientside script in their OnPrender event. So if we adding the validtion
controls correctly before Prerender, that should not be the problem.

I think we can first check whether the output page is correctly emiting the
validation's required script in page output and whether the script files on
the deployment server is correctly installed. As you mentioned that when
you're using the base page to adding those validation controls and the
validtion not work, have you tried viewing the page's output html code at
the clientside (via View source). You can have a look whether the script
codes are embeded correctly. If the code is correctly there, we may have a
check on the server's asp.net clientside script installation. Try
executing the
aspnet_regiis -c
command to reinstall the asp.net common script files on the server and test
again to see whether it works.

Anyway, I think it'll be better to start test from a simple page with a
textbox and a validtion control.

If there is any other findings, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Top