473,395 Members | 1,738 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,395 software developers and data experts.

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. CausesValidation 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 RegisterClientScript 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.com
Nov 18 '05 #1
4 10116
Page.RegisterStartupScript 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.google.c om...
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. CausesValidation 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 RegisterClientScript 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.com

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
CausesValidation=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.Redirect). Good luck in your efforts to implement your design. Let
us know the results.

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

<us*****@yahoo.com> wrote in message
news:27**************************@posting.google.c om...
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. CausesValidation 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 RegisterClientScript 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.com

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.com
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.google.c om...
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.com

Nov 18 '05 #5

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

Similar topics

2
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...
2
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 ......
1
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...
5
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...
8
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...
2
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...
0
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...
1
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...
2
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...
1
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...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.