473,804 Members | 3,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

newb: client script with asp.net

I need to add extensive validation and interaction client scripting to a web
form. I've done some initial searches for "asp.net and client scripting"
and I've found a couple articles that show methods like "register script
block" and what not. None of these methods will do what I need, I need to
add onChange, onClick, etc events to my controls.

For a simple example: How would I pop an alert when a user clicks on a
server textbox control?

Is this possible?

Thanks for any help,
Steve
Sep 15 '06 #1
3 1452
Steve,

Yes.

There are two aspects, one is Page validation and the other is validation of
the control.

I personally prefer to handle page validation with a "Can I Process?" sProc
so I can apply complex validation, that can change with scope creep and I
often don't have access to production WebServers, but do to databases, so I
can adapt my sProc business rules in the sProc's w/out having to rebuild the
project.

Anyway I've digressed....

Control events and validation are done with <asp:RequiredFi eldValidator... ..

Here's a textbox for entering the user's ID and on keyboard "Enter" posts,
this combined with the setFocus script makes logging in easy....

<asp:textbox id="tbId" onkeydown="if ((event.which &amp;&amp; event.which ==
13) || (event.keyCode &amp;&amp; event.keyCode == 13))
{document.Form1 .btnLogin.click ();return false;} else return true;"
runat="server" ToolTip="Enter Your Assigned ID" Width="126px"></asp:textbox>

or a more simple textbox....
<asp:textbox id="tbId" runat="server" ToolTip="Enter Your Assigned ID"
Width="126px"></asp:textbox>

<asp:requiredfi eldvalidator id="RequiredFie ldValidator1" runat="server"
ControlToValida te="tbId" Display="Dynami c"
ErrorMessage="Y ou must specify a ID.">*</asp:requiredfie ldvalidator>

Here is where the error msg displays, setting the validator to Dynamic
allows the error to hide this lable until re-evaluated.
<asp:Label id="lblInvalidL ogin" runat="server" ForeColor="Red"
Visible="False" >The ID entered was not valid.</asp:Label>

Regarding your registering a script, here's a call so that the cursor is in
the ID field in the pageLoad event

If Not Page.IsStartupS criptRegistered ("LoginFocusScr ipt") Then
Page.RegisterSt artupScript("Lo ginFocusScript" , Me.setLoginFocu sScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2******** ******@TK2MSFTN GP05.phx.gbl...
>I need to add extensive validation and interaction client scripting to a
web form. I've done some initial searches for "asp.net and client
scripting" and I've found a couple articles that show methods like
"register script block" and what not. None of these methods will do what
I need, I need to add onChange, onClick, etc events to my controls.

For a simple example: How would I pop an alert when a user clicks on a
server textbox control?

Is this possible?

Thanks for any help,
Steve

Sep 15 '06 #2
Jeff, thank you for the great response. I realize now that you can simply
add javascript to an asp server control directly in the HTML!

I was over complicating things :0)
"JeffP@Work " <jpgmt_at_sbcgl obal_dot_netwro te in message
news:eT******** ******@TK2MSFTN GP04.phx.gbl...
Steve,

Yes.

There are two aspects, one is Page validation and the other is validation
of the control.

I personally prefer to handle page validation with a "Can I Process?"
sProc so I can apply complex validation, that can change with scope creep
and I often don't have access to production WebServers, but do to
databases, so I can adapt my sProc business rules in the sProc's w/out
having to rebuild the project.

Anyway I've digressed....

Control events and validation are done with
<asp:RequiredFi eldValidator... ..

Here's a textbox for entering the user's ID and on keyboard "Enter" posts,
this combined with the setFocus script makes logging in easy....

<asp:textbox id="tbId" onkeydown="if ((event.which &amp;&amp; event.which
== 13) || (event.keyCode &amp;&amp; event.keyCode == 13))
{document.Form1 .btnLogin.click ();return false;} else return true;"
runat="server" ToolTip="Enter Your Assigned ID"
Width="126px"></asp:textbox>

or a more simple textbox....
<asp:textbox id="tbId" runat="server" ToolTip="Enter Your Assigned ID"
Width="126px"></asp:textbox>

<asp:requiredfi eldvalidator id="RequiredFie ldValidator1" runat="server"
ControlToValida te="tbId" Display="Dynami c"
ErrorMessage="Y ou must specify a ID.">*</asp:requiredfie ldvalidator>

Here is where the error msg displays, setting the validator to Dynamic
allows the error to hide this lable until re-evaluated.
<asp:Label id="lblInvalidL ogin" runat="server" ForeColor="Red"
Visible="False" >The ID entered was not valid.</asp:Label>

Regarding your registering a script, here's a call so that the cursor is
in the ID field in the pageLoad event

If Not Page.IsStartupS criptRegistered ("LoginFocusScr ipt") Then
Page.RegisterSt artupScript("Lo ginFocusScript" , Me.setLoginFocu sScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2******** ******@TK2MSFTN GP05.phx.gbl...
>>I need to add extensive validation and interaction client scripting to a
web form. I've done some initial searches for "asp.net and client
scripting" and I've found a couple articles that show methods like
"register script block" and what not. None of these methods will do what
I need, I need to add onChange, onClick, etc events to my controls.

For a simple example: How would I pop an alert when a user clicks on a
server textbox control?

Is this possible?

Thanks for any help,
Steve


Sep 15 '06 #3
NP

Also, the * asterisk is used as a tiny unassuming placeholder for the
lable....

JeffP....

"sklett" <s@s.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Jeff, thank you for the great response. I realize now that you can simply
add javascript to an asp server control directly in the HTML!

I was over complicating things :0)
"JeffP@Work " <jpgmt_at_sbcgl obal_dot_netwro te in message
news:eT******** ******@TK2MSFTN GP04.phx.gbl...
>Steve,

Yes.

There are two aspects, one is Page validation and the other is validation
of the control.

I personally prefer to handle page validation with a "Can I Process?"
sProc so I can apply complex validation, that can change with scope creep
and I often don't have access to production WebServers, but do to
databases, so I can adapt my sProc business rules in the sProc's w/out
having to rebuild the project.

Anyway I've digressed....

Control events and validation are done with
<asp:RequiredF ieldValidator.. ...

Here's a textbox for entering the user's ID and on keyboard "Enter"
posts, this combined with the setFocus script makes logging in easy....

<asp:textbox id="tbId" onkeydown="if ((event.which &amp;&amp; event.which
== 13) || (event.keyCode &amp;&amp; event.keyCode == 13))
{document.Form 1.btnLogin.clic k();return false;} else return true;"
runat="serve r" ToolTip="Enter Your Assigned ID"
Width="126px"> </asp:textbox>

or a more simple textbox....
<asp:textbox id="tbId" runat="server" ToolTip="Enter Your Assigned ID"
Width="126px"> </asp:textbox>

<asp:requiredf ieldvalidator id="RequiredFie ldValidator1" runat="server"
ControlToValid ate="tbId" Display="Dynami c"
ErrorMessage="Y ou must specify a
ID.">*</asp:requiredfie ldvalidator>

Here is where the error msg displays, setting the validator to Dynamic
allows the error to hide this lable until re-evaluated.
<asp:Label id="lblInvalidL ogin" runat="server" ForeColor="Red"
Visible="False ">The ID entered was not valid.</asp:Label>

Regarding your registering a script, here's a call so that the cursor is
in the ID field in the pageLoad event

If Not Page.IsStartupS criptRegistered ("LoginFocusScr ipt") Then
Page.RegisterS tartupScript("L oginFocusScript ", Me.setLoginFocu sScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2******* *******@TK2MSFT NGP05.phx.gbl.. .
>>>I need to add extensive validation and interaction client scripting to a
web form. I've done some initial searches for "asp.net and client
scripting" and I've found a couple articles that show methods like
"register script block" and what not. None of these methods will do
what I need, I need to add onChange, onClick, etc events to my controls.

For a simple example: How would I pop an alert when a user clicks on a
server textbox control?

Is this possible?

Thanks for any help,
Steve



Sep 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2133
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
5
2038
by: Alexandre | last post by:
Hi, Im a newb to dev and python... my first sefl assigned mission was to read a pickled file containing a list with DB like data and convert this to MySQL... So i wrote my first module which reads this pickled file and writes an XML file with list of tables and fields (... next step will the module who creates the tables according to details found in the XML file). If anyone has some minutes to spare, suggestions and comments would be...
3
6545
by: Sean Berry | last post by:
Hi there. I am relativly new to Python CGI and need a question answered. I have made custom 404 error pages and have them in various web directories. I have not been able to figure out a way to have apache use a file not within it's own home directory, so I was going to have a .py file in cgi-bin forward the user on to the correct error page.
1
1735
by: nightsaber | last post by:
<script language="JavaScript"> <!-- hide me var the_number = prompt("how many words (3-5 is good)?", "4"); var the_string = ""; var a_word; for (loop = 0; loop < the_number; loop++) { line_number = loop + 1;
3
1834
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
1
1099
by: Qwert | last post by:
Hello, two questions about the following code (.aspx file): Why doesn't the 'Text' property of control 'Label1' get changed in the function 'SetLabelText()'? How do I trigger the 'SetLabelText()' function when the mouse moves over the label control? The line code as below does not function. Thanks.
29
2667
by: jaysherby | last post by:
I'm new at Python and I need a little advice. Part of the script I'm trying to write needs to be aware of all the files of a certain extension in the script's path and all sub-directories. Can someone set me on the right path to what modules and calls to use to do that? You'd think that it would be a fairly simple proposition, but I can't find examples anywhere. Thanks.
2
1404
by: J | last post by:
Greetings Group- I'm trying to put together a pattern matching script that scans a directory tree for tif images contained in similar folder names, but running into a NewB problem already. Is it the way I'm trying to join multiple paths? Any help would be greatly appericated. Thanks, J! import glob, sys, os topdir = sys.argv
3
2071
by: DaveJ | last post by:
Hi everyone, I really was hesitant to post here for fear of seeming foolish but I really am desparate, and do appreciate any opportunity to get answers from real people. So please forgive the stupid questions. I just recently becan learning about WCF as a way to create web services. I had no prior experience developing web service architecture. My main question is very naive -- I hope someone can be kind enough to
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.