473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1433
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:RequiredFieldValidator.....

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:requiredfieldvalidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="tbId" Display="Dynamic"
ErrorMessage="You must specify a ID.">*</asp:requiredfieldvalidator>

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="lblInvalidLogin" 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.IsStartupScriptRegistered("LoginFocusScript") Then
Page.RegisterStartupScript("LoginFocusScript", Me.setLoginFocusScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2**************@TK2MSFTNGP05.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_sbcglobal_dot_netwrote in message
news:eT**************@TK2MSFTNGP04.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:RequiredFieldValidator.....

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:requiredfieldvalidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="tbId" Display="Dynamic"
ErrorMessage="You must specify a ID.">*</asp:requiredfieldvalidator>

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="lblInvalidLogin" 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.IsStartupScriptRegistered("LoginFocusScript") Then
Page.RegisterStartupScript("LoginFocusScript", Me.setLoginFocusScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2**************@TK2MSFTNGP05.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****************@TK2MSFTNGP04.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_sbcglobal_dot_netwrote in message
news:eT**************@TK2MSFTNGP04.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:RequiredFieldValidator.....

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:requiredfieldvalidator id="RequiredFieldValidator1" runat="server"
ControlToValidate="tbId" Display="Dynamic"
ErrorMessage="You must specify a
ID.">*</asp:requiredfieldvalidator>

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="lblInvalidLogin" 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.IsStartupScriptRegistered("LoginFocusScript") Then
Page.RegisterStartupScript("LoginFocusScript", Me.setLoginFocusScript)

HTH

JeffP....

"sklett" <s@s.comwrote in message
news:O2**************@TK2MSFTNGP05.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
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...
5
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...
3
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...
1
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++) {...
3
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...
1
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...
29
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...
2
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.