Java script

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Is it possible to call the javascript funtion from server side controls.

i have server side command button, when i click that buton it should call
javascript function and after that it should execute the server side code. is
it possible? can anyone give me a idea.

bala
 
Bala,

The answer is yes. In your code behind, you can add the javascript at run
time to the button. As an example, lets say you have a button called
btnSearch and you want to call a function called validateSearch() the code
would resemble the following in your page_load or something:

btnSearch.Attributes.Add("onClick", "validateSearch()");

Then for the server side click event, wire it as your normally would.

Thanks,
Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com - Aggregated Technology News
 
Thanks a lot Ian. its helps a lot.

Ian Suttle said:
Bala,

The answer is yes. In your code behind, you can add the javascript at run
time to the button. As an example, lets say you have a button called
btnSearch and you want to call a function called validateSearch() the code
would resemble the following in your page_load or something:

btnSearch.Attributes.Add("onClick", "validateSearch()");

Then for the server side click event, wire it as your normally would.

Thanks,
Ian Suttle
http://www.IanSuttle.com
http://www.NewsFuel.com - Aggregated Technology News
 
Here's some server side code that 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.
 
Back
Top