Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 26th, 2007, 9:10 AM   #1
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
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";
   }
   
   
}
paulchwd is offline   Reply With Quote
Old Sep 26th, 2007, 9:48 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Paul, do you understand the nature of the client/server paradigm?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 26th, 2007, 9:57 AM   #3
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
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)
paulchwd is offline   Reply With Quote
Old Sep 26th, 2007, 12:56 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Howzabout 'onclick = "validateMe ()";' and the last statement, if valid, is a submit?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 26th, 2007, 3:58 PM   #5
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,629
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
I think this is what you are looking for.
http://www.c-sharpcorner.com/UploadF...b-df0c669afd6c

which would be like using this (OnClientClick)
asp.net Syntax (Toggle Plain Text)
  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.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Oct 1st, 2007, 8:44 AM   #6
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
Perfect, thanks
paulchwd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Start Learning Java script smita JavaScript and Client-Side Browser Scripting 0 Mar 15th, 2007 7:47 AM
Hidden unless Javascript enabled? Writlaus JavaScript and Client-Side Browser Scripting 3 Apr 25th, 2006 10:52 PM
Javascript alternative? Writlaus JavaScript and Client-Side Browser Scripting 32 Apr 21st, 2006 12:44 AM
HTML page not reading external Javascript file aznluvsmc JavaScript and Client-Side Browser Scripting 9 Nov 21st, 2005 9:17 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:52 AM.

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