473,732 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ClientScri pt.RegisterClie ntScriptBlock 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 2864
Hi,

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

Page.ClientScri pt.RegisterOnSu bmitStatement(M e.GetType(), "validcheck ",
"if(!Page_IsVal id){alert('Vali dation 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.ClientScri pt.RegisterClie ntScriptBlock 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*******@hotm ail.comwrote in message
news:6E******** *************** ***********@mic rosoft.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.ClientScri pt.RegisterClie ntScriptBlock 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:

RegisterClientS criptBlock - javascript appears after <form(before form
element defined.

RegisterStartup Script - javascript appears just before </form(after
form elements defined.

RegisterOnSubmi tStatement - 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.ClientScri pt.RegisterClie ntScriptBlock 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 RegisterOnSubmi tStatement
method..

--Papanii

"Papanii" <pa*******@hotm ail.comwrote in message
news:6E******** *************** ***********@mic rosoft.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.ClientScri pt.RegisterClie ntScriptBlock 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
4081
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 dependant on data collected in the code behind on the server. I have set AutoPostback to false for the controls and added lines such as cboMyCombo1.Attributes.Add("onchange", "MyCombos_OnChange('1')"); in the Page_Load event, which is rendered OK...
2
5982
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 need the clientside script to run when the selected radio button changes, but I'm having trouble registering onclick events with each of the radio buttons. I've tried registering an onclick attribute with each item: item.Attributes +=...
8
11164
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 has it's own event and autopostback=true) before clicking submit then it fires the text box event but never fires the btnSubmit event. (I follow it in the trace). Surely both event handlers should be fired? Any hints on identifying what I
2
1998
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 Page_Load event immediately fires on the codebehind page and then click event fires. When this happens, the Page.IsPostBack property is true in the page_load event. Why is the page_load event firing before the ImageButton_Click event?
4
3771
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 always fires first in Firefox (the desired behaviour). Do I have any guarantee that this ordering will be the same across other browsers?
10
2614
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 gets set to false, yet the javascript clientvalidationfunction is firing when the cancel button is hit. Running through the debugger, the CausesValidation property is set to false on the Page_Load of the derived form. Why is the clientside...
19
10206
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 app using web application projects and it's firing fine but it was upgraded from the 1.1 framework. Why doesn't my global.asax application_error routine fire?
2
2850
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 need some custom javascript validation on form submit but why does is kill the submit button event handler? Submit buttons don't use __doPostBack so what is being effected?
1
2361
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 DNS name is "cati", the names are specified in the "Last_names" field, and the categories are in the "categories" field. l want the results sorted in alphabetic order by last name. However, the results appear to be in a totally random,...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.