?
Solved

Adding customised javascript on Submit button before postback?

Posted on 2004-11-18
3
Medium Priority
?
1,144 Views
Last Modified: 2008-02-26
Hi there,

Created a webform (asp.net c#)

<form id=Form1 method=post runat="server">

with the following submit button

<asp:Button id=searchButton runat="server" Text="Search"></asp:Button>

Basically when you click the searchButton (submit) button then it does a postback, everything is working but what I want to do is run some javascript prior to doing the postback.

The javascript (clientside) will check some values of textboxes etc and if they are valid then the POSTBACK will continue otherwise I will display to the user "Sorry please check the form" and postback is cancelled.

Wow! I don't even know where to start on this, can anybody help?

I have written the javascript clientside code, it is in a function called "CheckThisNow"

Any ideas of where to start on this? Appreciated any input anyone has, or any documents you can point me in the direction of.

Ian
0
Comment
Question by:ianinspain
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 2000 total points
ID: 12615197
Hi ianinspain,

Sub Page_Load
    searchButton.Attributes.Add("onclick", " return CheckThisNow();")
End Sub

this will add the client event to the button and if the CheckThisNow return false, the submit will not be proceeded


Regards!
B..M
mmarinov
0
 

Author Comment

by:ianinspain
ID: 12624613
Hi mmarinov,

Cool! as simple as that... going to give it a try..

I presume i just use this to add to a submit button, all my javascript functions still need to be embedded within the HTML between tags as normal?

Cheers
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12624659
yes, you have to put your javascript code in the HTML

B..M
mmarinov
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question