Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is client side vbscript so hard for aspx?

Status
Not open for further replies.

Custom24

Programmer
Nov 27, 2001
591
GB
Hi
I've a similar question to thread855-323022 (Isadore)

I need to use client side vbscript to do some stuff. Maybe I'm not getting the asp.net idea.

Suppose I've got a text box where I want the user just to enter a five digit number. In classic asp, this just meant writing a client side vbscript sub for the key press event to make sure the key in was numeric.

In .net, I would like this control to be a web control, since then I would have control of it on the server as well. But I don't want autopostback on.

It seems that client side code does not work for aspx pages, and the solution in thread855-323022 seemed too complicated - why have MS made it this hard?

Thanks for listening
Mark
 
Client side actions have gotten more difficult, but there's a huge payoff. For your misery there, you gain

(a)infinitely more elegant programming model for the web -- for server side actions, that is
(b)greatly increased performance
(c)a true oo language for your web developing pleasure
etc....

My advice would be to just implement the solution you mentioned there. It's really not that tough. Please refer to the corrected version of the client side script to avoid the headaches that we encountered to get there, though.

:)
paul
penny1.gif
penny1.gif
 
Paul
Thanks for that.

I really could not believe that this was the case, though, and I think there is an easier way. All the client sees if plain old HTML at the end of the day, and as long as you prefix the names of the controls with the form name, you can do whatever you like client-side.

For example, you can include a HTML text input element in an aspx page and still code against it client side

eg
sub txtClient_onkeypress
msgbox form1.txtWebControl.value
end sub

And you can do the same thing for a web control, since it ends up being a regular text element

Finally, even if you use HTML elements, you can still use classic ASP techniques to query them server side.

I keep finding myself fighting this ASP.net business - it's kind of a love/hate relationship, so thanks for reminding me in your post of why it is worth struggling with :>

Mark
 
msgbox form1.txtWebControl.value

won't work just like that if the control is a web control (asp:textbox, for instance).

The reason is that asp.net renames them to ensure unique ids for all controls. It must be this way in case you decide to start nesting user controls on a page -- in that case if they didn't, you would get id collisions and everything would break.

I really do think that the solution I posted is about the best we're going to be able to do to get at those objects once asp.net renames them, since you can't really judge the ordinal position of elements at design time, either because asp.net throws stuff in there that you may or may not expect.

Anyway... that's why the solution is as complicated as it is, but still not too bad, I think. Just harder than it used to be.

:)
paul
penny1.gif
penny1.gif
 
For this particular case of form validation, you don't have to write custom client-side script. Use the ASP regular expression validator. The framework will send javascript to uplevel browsers and will validate all submissions server-side (new and old browsers).

You can disable autopostback per control by adding the autopostback="false" attribute to the tag (or set it in the properties dialog in designer mode).

If you really want to add client-side events manually, use an HTML control (
Code:
<input onblur=&quot;myvalidate&quot; id=&quot;text1&quot; runat=&quot;server&quot; />
) rather than a server control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top