473,722 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to have onsubmit event fire after server-side validation.

Hi folks,

I appreciate any assistance in the following problem:
I have a form with a bunch of dynamic controls on it. All the controls
are dynamically generated on a server, including all the validators.

The user enters the data, presses OK. My OK button is dynamically
generated as well, with some code-behind logic in
it's click event. CausesValidatio n property is set to false, since all
my validators are dynamic anyways,
and I do all my validation on a server. In the beginning of an
OK_click event, I call page validate explicitly:
Page.Validate() ;
if (!IsValid) return;

So far, so good. Now, in the beginning of my OK logic, I need to call
some javascript function, that will take some parameters,
call Modal Dialog and return some parameters to the server.

I attached this function to form OnSubmit event:
<form id="Form1" method="post" runat="server" onsubmit="test( )">

Everything is great, I'm able to call the function that calls modal
dialog, grab a return value, set it
to a hidden field, and pick it up on a server.

The only one thing that I cannot figure out how to do, is: I want my
function to be called only AFTER the
validation, and only if validation is correct. I cannot figure out how
it do it, and if its possible.

My function keeps getting called before the validation.

I searched on the internet about this problem, and it seems like
people who had it and successfully resolved
it, all had client-side validation. But I have a server-side
validation.

I tried to mess with different things, like putting the javascript
function call in ResponseWrite, or
registering it with RegisterClientS cript and
then calling it explicitly after Page.Validate() , but it doesn't work
anyway, it's even worse, because, now
javascript is executed in the very beginning of the form, before all
the controls are created, so I don't
have my hidden field control yet, to pass the information to the
server.

Is there any way? I appreciate your time, folks.
us*****@yahoo.c om
Nov 18 '05 #1
4 10145
Page.RegisterSt artupScript puts the javascirpt at the end of the page, after
all controls have loaded. I use this to execute javascript after a
validation event is ok. You can then access the values of the controls.

Earl
<us*****@yahoo. com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
Hi folks,

I appreciate any assistance in the following problem:
I have a form with a bunch of dynamic controls on it. All the controls
are dynamically generated on a server, including all the validators.

The user enters the data, presses OK. My OK button is dynamically
generated as well, with some code-behind logic in
it's click event. CausesValidatio n property is set to false, since all
my validators are dynamic anyways,
and I do all my validation on a server. In the beginning of an
OK_click event, I call page validate explicitly:
Page.Validate() ;
if (!IsValid) return;

So far, so good. Now, in the beginning of my OK logic, I need to call
some javascript function, that will take some parameters,
call Modal Dialog and return some parameters to the server.

I attached this function to form OnSubmit event:
<form id="Form1" method="post" runat="server" onsubmit="test( )">

Everything is great, I'm able to call the function that calls modal
dialog, grab a return value, set it
to a hidden field, and pick it up on a server.

The only one thing that I cannot figure out how to do, is: I want my
function to be called only AFTER the
validation, and only if validation is correct. I cannot figure out how
it do it, and if its possible.

My function keeps getting called before the validation.

I searched on the internet about this problem, and it seems like
people who had it and successfully resolved
it, all had client-side validation. But I have a server-side
validation.

I tried to mess with different things, like putting the javascript
function call in ResponseWrite, or
registering it with RegisterClientS cript and
then calling it explicitly after Page.Validate() , but it doesn't work
anyway, it's even worse, because, now
javascript is executed in the very beginning of the form, before all
the controls are created, so I don't
have my hidden field control yet, to pass the information to the
server.

Is there any way? I appreciate your time, folks.
us*****@yahoo.c om

Nov 18 '05 #2
I agree with Earl's solution. Let me give you some background because you
are stating things that seem incorrect.

1. There is no way to call javascript from within your server side code.
2. If you have stopped client-side validation through
CausesValidatio n=false, the button will not generate code that runs
validation. However, the <form onsubmit= > statement will still create some
code that is used by validation to determine if the page submits. The
button's code sets a global variable Page_IsValid. When false, onsubmit is
stopped.
3. The order of events as you've described them makes no sense. If
Page.Validate() is called first, then the page had to be submittted (it gets
passed the onsubmit= attribute) to the server for processing. Yet, you are
concerned about your javascript occurring after. Your javascript will not
run until the page reloads on the client, long after the server is done
generating it. If you place is in the onsubmit attribute, it will only run
when a submit button is clicked.

As a result, Earl has you add the Javascript to the page in a location where
it will run immediately after the page is loaded into the browser.

This page design is not that easy to manage, as you can see. Most users
redirect to a new page after validation to handle the extra elements that
your modal dialog would cover. They would pass along values using the
QueryString or ViewState (this needs you to use Server.Transfer instead of
Response.Redire ct). Good luck in your efforts to implement your design. Let
us know the results.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

<us*****@yahoo. com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
Hi folks,

I appreciate any assistance in the following problem:
I have a form with a bunch of dynamic controls on it. All the controls
are dynamically generated on a server, including all the validators.

The user enters the data, presses OK. My OK button is dynamically
generated as well, with some code-behind logic in
it's click event. CausesValidatio n property is set to false, since all
my validators are dynamic anyways,
and I do all my validation on a server. In the beginning of an
OK_click event, I call page validate explicitly:
Page.Validate() ;
if (!IsValid) return;

So far, so good. Now, in the beginning of my OK logic, I need to call
some javascript function, that will take some parameters,
call Modal Dialog and return some parameters to the server.

I attached this function to form OnSubmit event:
<form id="Form1" method="post" runat="server" onsubmit="test( )">

Everything is great, I'm able to call the function that calls modal
dialog, grab a return value, set it
to a hidden field, and pick it up on a server.

The only one thing that I cannot figure out how to do, is: I want my
function to be called only AFTER the
validation, and only if validation is correct. I cannot figure out how
it do it, and if its possible.

My function keeps getting called before the validation.

I searched on the internet about this problem, and it seems like
people who had it and successfully resolved
it, all had client-side validation. But I have a server-side
validation.

I tried to mess with different things, like putting the javascript
function call in ResponseWrite, or
registering it with RegisterClientS cript and
then calling it explicitly after Page.Validate() , but it doesn't work
anyway, it's even worse, because, now
javascript is executed in the very beginning of the form, before all
the controls are created, so I don't
have my hidden field control yet, to pass the information to the
server.

Is there any way? I appreciate your time, folks.
us*****@yahoo.c om

Nov 18 '05 #3
Earl, Peter,

thanks for answering.
I understood your explanation, Peter. I got confused at first, I
guess. I guess i had no idea what I
was doing.
I'm gonna use your advice
and try to implement Server.Transfer method. Actually, I will do
Server.Execute, because one thing
I forgot to mention in my email, is that I need to call Javascript,
not only AFTER the validation,
but BEFORE the code that follows validation.

So I have in on_click event:
{
<some server code>
Page.Validate() ;
if (!IsValid) return;
<have to call javascript right here>
<some server code>
}
So I have to call javascript and resume right at the point i left off.
After your explanation I
understood that there's no way in freeking hell to do it, like I was
trying to do.
I could manage to not call javascript if validation failed, by setting
some hidden field variable
to false, and reading it in a javascript, but if the validation
succeeded, there's no way I could
call javascript right after the validation, and before the rest of the
code, because the entire
server logic will be executing first,and only then, the client will
run javascript.

So that seems the only option for me, to use ServerExecute, to go to
some aspx page that will, in turn,
call the javascript.

Many thanks to both of you, again,
us*****@yahoo.c om
Nov 18 '05 #4
that won't work either. the only way to call javascript from the server, is
to send a page back to the client that execute the javascript, then the
javascript auto posts the page back. the second postback will be a different
page request.

-- bruce (sqlwork.com)


<us*****@yahoo. com> wrote in message
news:27******** *************** ***@posting.goo gle.com...
Earl, Peter,

thanks for answering.
I understood your explanation, Peter. I got confused at first, I
guess. I guess i had no idea what I
was doing.
I'm gonna use your advice
and try to implement Server.Transfer method. Actually, I will do
Server.Execute, because one thing
I forgot to mention in my email, is that I need to call Javascript,
not only AFTER the validation,
but BEFORE the code that follows validation.

So I have in on_click event:
{
<some server code>
Page.Validate() ;
if (!IsValid) return;
<have to call javascript right here>
<some server code>
}
So I have to call javascript and resume right at the point i left off.
After your explanation I
understood that there's no way in freeking hell to do it, like I was
trying to do.
I could manage to not call javascript if validation failed, by setting
some hidden field variable
to false, and reading it in a javascript, but if the validation
succeeded, there's no way I could
call javascript right after the validation, and before the rest of the
code, because the entire
server logic will be executing first,and only then, the client will
run javascript.

So that seems the only option for me, to use ServerExecute, to go to
some aspx page that will, in turn,
call the javascript.

Many thanks to both of you, again,
us*****@yahoo.c om

Nov 18 '05 #5

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

Similar topics

2
2996
by: Chris | last post by:
I am wondering about what seems to be a particular quirk in Javascript that does not allow form event listeners (e.g. "onsubmit=...") to work properly. In the code below, I would like to set up a function (doOnSubmit) that is called when the form is submitted. But there is a "return false;" in the "onclick" of the button. If this "return false" is removed, the code works as I would hope it would. With it there, doOnSubmit is never...
2
6469
by: Sean Dockery | last post by:
Which is the following is correct? a) <form ... onSubmit="return checkData()"> b) <form ... onSubmit="return checkData();"> c) <form ... onSubmit="checkData()"> d) <form ... onSubmit="checkData();">
1
2594
by: Duwayne | last post by:
I am having a lot of trouble with an ascx page that has a textbox that *should fire a textchange event when the text changes. The main aspx page dynamically loads the ascx page and has a image button that initiates the submit. during submit, 2 events *should fire, 1 from the textbox and 1 from the image button. The image button event always fire but the textbox textchange event does not. Anyone has any ideas? Notes: During postback, I...
5
1651
by: LL | last post by:
Hi, I use Applicaiton lever variable like this: Application = xxx; Do I need to restart the WWW service every time to reset it? I also have several Session variables. When Session_End event fire, all of them are null, right? Thanks.
8
4314
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
2
2405
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe that I am not calling the function correctly. The MyInsertMethod function is the function that comes in the Web Matrix Toolbox <%@ Page Language="VB" %>
0
1390
by: John A Grandy | last post by:
For a <form method="get"containing an <input type="text", a <select, and an <input type="submit"....... I find that the form's onsubmit event is triggered by pressing enter if the focus is on the textbox , but not if the focus is on the dropdown. Does anyone know why this is and how to fire the onsubmit event on pressing enter if the dropdown has the focus ?
1
1342
by: Josh | last post by:
I'm trying to trigger an onSubmit function from a form using Javascript. As far as I know the only way to do this is to hide a submit button and then use 'button'.click() on the submit button to fire the onSubmit event. Unfortunately I'm getting a permissions Javascript error, has anyone experienced this before and fixed it? Thanks.
2
2738
by: Michal Valent | last post by:
I would like to fire some custom server control event before Page_Load event like this (from the trace of an aspx page) : Trace Information Category Message From First(s) From Last(s) aspx.page Begin PreInit aspx.page End PreInit 5,38454603734274E-05 0,000054 aspx.page Begin Init 8,96405962016187E-05 0,000036 aspx.page End Init 0,00072941040948794 0,000640 aspx.page Begin InitComplete 0,000772971258380746 0,000044
1
1943
by: vunet | last post by:
I write a JS library component which is applied to every form on a webpage. The component does something before it submits the form. Now, let's say user has his own onSubmit() handlers returning true or false. I want to find a way to add my component's "onsubmit" event to the form without overwriting user-defined onSubmit() handlers or onsubmit events. Is there a really good way of doing this? The problem I've come across was if I add...
0
8740
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9239
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...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5996
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
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
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
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2148
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.