473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.
Thanks
--Papanii

May 29 '07 #1
3 2854
Hi,

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.Get Type(), "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
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Papanii" <pa*******@hotmail.comwrote in message
news:6E**********************************@microsof t.com...
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.
Thanks
--Papanii

May 29 '07 #2
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
form.submit

-- bruce (sqlwork.com)

Papanii wrote:
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.
Thanks
--Papanii
May 29 '07 #3
Thanks a lot guys, i totally forgot about the RegisterOnSubmitStatement
method..

--Papanii

"Papanii" <pa*******@hotmail.comwrote in message
news:6E**********************************@microsof t.com...
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.
Thanks
--Papanii
May 29 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
2
by: Helen | last post by:
I've got some clientside script that runs when the selected index of a select box changes. Now I need to swap my selectbox with an ASP.NET radiobuttonlist (to solve some layout issues). I still...
8
by: walesboy | last post by:
greetings - I have a btnSubmit button with a Handles btnSubmit.click which works great if all the user does is click that button. But, if the user ALSO changes a text box on the page (which...
2
by: Dan | last post by:
I have an aspx page with a form on it. There are a couple of textboxes and an ImageButton. The page is loaded from another page using Server.Transfer. When I click on the ImageButton, the...
4
by: Adam Ratcliffe | last post by:
I have 2 onload handlers on a web page. One is set programatically in an included script and the other declared on the document's body element. In practice the programatically set onload handler...
10
by: mwieder | last post by:
I've got an ASP.NET form with a textbox and a customvalidator. The form inherits from a base wizard class with back, next and cancel buttons. The CausesValidation property of the Cancel button...
19
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another...
2
by: APA | last post by:
Why does adding code to the form submit function using the RegisterOnSubmitStatement method prevent the server side event handler for the submit button from firing? This is completely useless. I...
1
by: Brit | last post by:
I have an ASP file that retrieves names from an Access database for 4 different categories of membership, which the visitor to the page selects (corporate, institutional, regular, or student). The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.