Connecting Tech Pros Worldwide Forums | Help | Site Map

how can call a funtion on click event of a button in asp,

Newbie
 
Join Date: Aug 2009
Posts: 1
#1: Aug 6 '09
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=javascript %>
  2.  
  3. <HTML>
  4. <HEAD>
  5. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  6.  
  7.  
  8.  
  9. </HEAD>
  10. <BODY>
  11. <% 
  12.   function validate()
  13.   {
  14.     alert("all field must be fillup")  
  15.   }
  16. %>
  17.  
  18. <FORM  action="get.asp" method="post">
  19. <center>
  20. <table border="1" cellspacing="0" cellpading="0">
  21.    <tr>
  22.         <td style="FONT-SIZE: medium; COLOR: royalblue" >
  23.         Customer Name </FONT>
  24.         </td>
  25.         <td>
  26.        <input name="txtName" size="15" >
  27.        </td>
  28.    </tr>
  29.    <tr>
  30.        <td style="COLOR: royalblue">
  31.        Customer Address
  32.        </td>
  33.        <td>
  34.        <input name="txtAdd" size="15" 
  35.      >
  36.        </td>
  37.    </tr>
  38.    <tr>
  39.        <td style="COLOR: royalblue">
  40.        Customer PhoneNo.
  41.        </td>
  42.        <td>
  43.        <input name="txtPhone"   
  44.       size="15" maxLength=10>
  45.        </td>
  46.   </tr>
  47.        <tr>
  48.        <td style="COLOR: royalblue">
  49.        Customer EmailId
  50.        </td>
  51.        <td>
  52.        <input type="tex" name="txtEmailid" size="15" >
  53.        </td>
  54.   </tr>
  55.    <tr>
  56.        <td align="right">
  57.        <input type="button" name="button1" value="Cancel" style="FONT-WEIGHT: bold; FONT-VARIANT: normal" onClick="return validate()" >
  58.        </td>
  59.         <td>
  60.         <input type="submit" value="Submit"  name="submit"  style="FONT-WEIGHT: bold; FONT-STYLE: normal" >
  61.         </td>
  62.   </tr>
  63.      </table> 
  64.    </center>
  65.  
  66. </FORM>
  67.  
  68. </BODY>
  69. </HTML>

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,691
#2: Aug 7 '09

re: how can call a funtion on click event of a button in asp,


Hi and welcome to Bytes.

This is a common question, and the simple answer is that you can not. ASP runs on the server BEFORE it is sent to the user. No ASP code can execute AFTER the user receives it. We use javascript, ajax, or CSS or some such to execute code after the browser receives the page.

Can ASP experts get around that difficulty? Yes. One of the simplest ways to do it is to have a frame on the page, when the button is clicked, code is sent to refresh that frame. You can send the information for the function you want to call in the code to refresh the page. Does this make sense?

If you need further help, please explain what you are trying to do.

Jared
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 145
#3: Aug 7 '09

re: how can call a funtion on click event of a button in asp,


Quote:
One of the simplest ways to do it is to have a frame on the page, when the button is clicked, code is sent to refresh that frame.
Concurred. I've used that method a few times myself, mostly on admin panels.

I am becoming a fan of the AJAX method tho' especially when using jQuery :)

Gaz
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,691
#4: Aug 7 '09

re: how can call a funtion on click event of a button in asp,


Quote:

Originally Posted by GazMathias View Post

Concurred. I've used that method a few times myself, mostly on admin panels.

I am becoming a fan of the AJAX method tho' especially when using jQuery :)

Gaz

Yeah, I need to learn Ajax, unfortunately it's not yet at the top of my list.

Jared
GazMathias's Avatar
Expert
 
Join Date: Oct 2008
Location: Bristol, United Kingdom
Posts: 145
#5: Aug 7 '09

re: how can call a funtion on click event of a button in asp,


Here's a simple call to page to fill a div in jQuery:

Expand|Select|Wrap|Line Numbers
  1. $.ajax({
  2.         type: "GET",
  3.         url: "viewproducts.asp",
  4.         data: "product=<%=rs("productid")%>",
  5.         success: function(html){
  6.         $("#ProductDetail").html(html);
  7.         }
  8.     });
  9.  
Simple, but extremely effective.

Gaz.
Reply


Similar ASP / Active Server Pages bytes