![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
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";
}
} |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
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) |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
PFO Founder
![]() ![]() |
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)
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. |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Perfect, thanks
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |