469,578 Members | 1,583 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

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 1326
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by claudel | last post: by
5 posts views Thread by Alexandre | last post: by
3 posts views Thread by Sean Berry | last post: by
3 posts views Thread by claudel | last post: by
1 post views Thread by Qwert | last post: by
29 posts views Thread by jaysherby | last post: by
2 posts views Thread by J | last post: by
3 posts views Thread by DaveJ | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.