Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   ASP.NET (http://www.programmingforums.org/forum35.html)
-   -   javaScript (http://www.programmingforums.org/showthread.php?t=14043)

paulchwd Sep 26th, 2007 10:10 AM

javaScript
 
Hi...

I have an aspx page and a c# codebehind. How can I call a javaScript function before the codebehind is executed. I used the 'standard' controls (visual studio 2005 professional) so that when i double click on the control ie: a button the event code is generated in the c# codebehind...

I have a javaScript function called validateMe() and in the standard control's tag in the aspx file i add onclick="validateMe()" and i receive an error saying there is no such function



1. What is the difference between the 'standard' controlls in visual studio and the html controlls in visual studio ?

2. I have a standard button on my form. I tried adding onsubmit="validateMe()" and it did not get triggered -- but i got an error that such function doesnt exist

Thnx

:

  <asp:Button ID="submit" onclick="validateMe()" runat="server" BackColor="Highlight" BorderColor="White"

:

function validateMe()
{
//Price
alert('yy');
  var price = document.getElementById('price')
  if(price.value.indexOf("$") == -1)
  {
      price.value.repalce("$", "");
  }
  if(price.value.indexOf(".") == -1)
  {
      price.value = price.value & ".00";
  }
 
  var regDecimal = new RegExp("^[0-9]+\.{1}[0-9]+$");
 
  if(!regDecimal.test(price)
  {
        var price_errDiv = document.getElementById('price_err');
        price_errDiv.style.visibility="visible";
  }
 
 
}


DaWei Sep 26th, 2007 10:48 AM

Paul, do you understand the nature of the client/server paradigm?

paulchwd Sep 26th, 2007 10:57 AM

Ah DaWei,

I do understand the seperation of client server, my problem is i am new to ASP.net and my way of thinking is more that of ASP.

How can I cause my client side validation script to execute before the server-side cs program is executed. In classic ASP i wold put 'onsubmit="validateMe()" to the form tag. But it seems that the button I added isnt a 'submit' button... its a 'standard' control (in visual studio)

DaWei Sep 26th, 2007 1:56 PM

Howzabout 'onclick = "validateMe ()";' and the last statement, if valid, is a submit?

big_k105 Sep 26th, 2007 4:58 PM

I think this is what you are looking for.
http://www.c-sharpcorner.com/UploadF...b-df0c669afd6c

which would be like using this (OnClientClick)
:

  1. <asp:Button ID="submit" OnClientClick="return validateMe()" runat="server" BackColor="Highlight" BorderColor="White"


If true is returned then it will submit I believe and if false then it won't.

paulchwd Oct 1st, 2007 9:44 AM

Perfect, thanks


All times are GMT -5. The time now is 2:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC