client side script, then server side

M

Mortar

i have a server side button which 1st needs to run some client side
script for form checking. I got this working from the attributes
thing.

Then, if all is valid client side, i need to call the server side
function for the button. I can't just do a submit because that won't
call the server function. Anyone know how to do this?
 
D

darrel

i have a server side button which 1st needs to run some client side
script for form checking. I got this working from the attributes
thing.

Then, if all is valid client side, i need to call the server side
function for the button. I can't just do a submit because that won't
call the server function. Anyone know how to do this?

It sounds like you have a form, and, if the form is valid, you want
something to happen, correct?

If so, in the button click function, you'd do something like this:

page.validate

if page.isvalid then...
do your thing
else
don't do it
end if

-Darrel
 
S

Steve C. Orr [MVP, MCSD]

You might want to use the built in ASP.NET validation controls, since they
provide this kind of functionality.

If your needs are modest, the code below may get you started:

This server side code uses javascript to display a confirmation message.
myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.
 
R

Ryan Trudelle-Schwarz

i have a server side button which 1st needs to run some client side
script for form checking. I got this working from the attributes
thing.

Then, if all is valid client side, i need to call the server side
function for the button. I can't just do a submit because that won't
call the server function. Anyone know how to do this?

Assuming your control like so:

<asp:button id="someButton" runat="server" />

add an onclick attribute like: "return isValid();"
(so the output should be <inut type="submit" id="someButton" onclick="return
isValid();" />)

and define a function like:
"function isValid()
{
if(something is valid)
return true;
else
return false;
}"

when you return false from the isValid, the click event is aborted so the
form will not submit. If you return true, the event will continue processing
and the form will be submitted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top