Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

firing order fo clientSide script

Hello Guys,
              I have a little problem that i need some ideas as to how to
solve. I have a form that sends some data to the server once filled. Now,
for this form i am using asp.net validation controls to ensure certain
fields are filled and also have the correct data format.  What i want to
have happen is once the form has been validated and the submit button
clicked,  i want a javascript function to fire before continuing with the
server side code. Now, i thought that using the submit button's
onclientClick property would work for this however, this fires the
javascript function regardless of whether or not the validation is
successful. So i decided to add the
Page.ClientScript.RegisterClientScriptBlock at the begining of the server
side code however this only seems to fire after the server side code
completes. I am assuming it has something to do with the switching of
running thread within the process however i am not sure. Does anyone have an
idea as to how i can get the javascript code to run only after validation is
successful  but before the server side code runs.



that means you'd rely only on the client-side validation(since you want the
msg to appear before the postback occurs and before server-.side validation
whatsoever). If that's acceptable, you could use RegisterOnSubmitStatement

Page.ClientScript.RegisterOnSubmitStatement(Me.GetType(), "validcheck",
"if(!Page_IsValid){alert('Validation failed');return false;}")

Run it in Page_Load (or at PreRender at the latest) so that it's registered
by the time page is rendered

Of course, you could use this trick with buttons too, since it uses
client-side Page_IsValid variable (part of client validation library) to
check if client-side validation passed or not.

 Page.ClientScript.RegisterClientScriptBlock is meant to generate script
calls from server-side code, and as you can understand they run at the
client...which gets it when server-side code is done and page is rendered

Teemu Keiski
AspInsider, ASP.NET MVP

"Papanii" <papani@hotmail.com> wrote in message


there are three spots that asp.net supports adding script:

RegisterClientScriptBlock - javascript appears after <form> (before form
element defined.

RegisterStartupScript - javascript appears just before </form> (after
form elements defined.

RegisterOnSubmitStatement - javascript eval'd after validation, before

-- bruce (sqlwork.com)

Thanks a lot guys, i totally forgot about the RegisterOnSubmitStatement


"Papanii" <papani@hotmail.com> wrote in message


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc