Documente Academic
Documente Profesional
Documente Cultură
this
includes a set of server-based controls that are analogous to html form elements
such as text boxes, buttons, and so forth. the problem with these controls is the
need to call the server. javascript provides an alternative for many tasks that
negates the need to go to the server. let's take a closer look at combining the
power of javascript with asp.net.
performance is a must
making calls to the server requires bandwidth and server processing time. this may
not be a problem with an intranet application, which has the advantage of a high-
speed lan, but an internet application is a different story. an internet user's
connection speed varies depending on whether the user has a dial-up modem, dsl, or
a cable modem. utilising client-side javascript negates the need for a server
round-trip.
function valsubmit() {
var doc = document.forms[0];
var msg = "";
if (doc.firstname.value == "") {
if (doc.lastname.value == "") {
msg += "- please enter a last name.n";
}
if (msg == "") {
doc.submit();
} else {
alert("the following errors were
encountered.nn" + msg);
} }
this function verifies that values are entered into two html fields on the form.
if either field is empty, an error message displays and execution stops. if both
fields are populated, the form is submitted. you may call this function from an
html button with the following code:
with this relationship, the form isn't submitted to the server until the fields
are populated. the code may be simple, but it doesn't have any adverse effect on
performance since no extra server calls are necessary; and the javascript code is
short and sweet, which means the form doesn't require additional load time. this
solution utilises normal html form elements, but using it with an asp.net web form
isn't as straightforward.
the button control's attributes property provides a way to tie javascript to the
control. first, the javascript function is placed on the asp.net web form, but
it's altered in a particular way: a return value is added. the function returns
true if the validation is successful; this signals that the form may be submitted
to the server. the submission to the server signals that the server function
associated with the button is called. a return value of false signals the function
failed, so the form isn't submitted.
the elements are placed on the html form using css via their style attribute. the
form ties the javascript function to the asp.net button (btnsubmit) and to its
html onclick event. the onclick attribute of the asp.net button tells the system
what function is called when the form is submitted to the server.
if you're a vb.net developer, the only change to the previous code is the c# block
of code. the vb.net version follows:
a powerful combination
javascript is the de facto standard for client-side web development. combining it
with asp.net web forms provides the developer with a powerful set of tools for
building robust applications that consider performance a key ingredient.
* print this
* e-mail this
* leave a comment
* clip this
*
close
do you need help with .net? gain advice from builder au forums
* related links
* comments
1
oscar spila - 07/10/04
2
tejas shah - 12/02/05
hello evreyone
i also have the same problem
but i also want to get back the return value of function.
then how can i get that valuewith vb.net in asp.net
thanks in advance
� report offensive content
3
bradley thomas - 18/04/05
this article shows what i find everywhere on the web, how to link from your
asp.net page to your html/javascript page, but not the other way around. i would
love to know how to get details that have been changed through javascript back to
my asp.net page so that they may be stored in the database. how do i do this
� report offensive content
4
ravi - 28/04/05
how to access c# label controls in javascript. all other controls i can access
only lables i cant. please help.
� report offensive content
5
steven oesterreicher - 04/10/05
isn't using java script frowded upon because you don't know whether a client has
java script turned on?
� report offensive content
6
rajib ahmed - 10/05/06
using javasript is not frowned upon. client side validation is necessary, but
doesn't imply server side validation is not. it only makes applications stronger
to have validation on both sides. if you are using client/server side validation,
make sure in you vb.net or c# code checks if the page is valid. (page.isvalid)
� report offensive content
7
sagar - 21/07/06
hello everyone,
i want to add a javascript function on my project's one .aspx file to validate a
textbox so that the charector '&' should not be entered in it
� report offensive content
8
newasp.netter - 11/08/06
9
smruti ranjan rout - 14/08/06
hello everyone
if i want call a java script function in onclick of a button attribut,
if i am writing btnsubmit.attributes.add("onclick","return
checkrequiredfield();");
10
bill donnelly - 06/09/06
in my situation, i have some logic which occurs as the page (c#/asp.net) gets
loaded (it determines whether the record the user is trying to edit is locked by
another user).
i want to give the user the opportunity to take some action; the only way to get a
yes/no answer (afaik) is to use a javascript confirm() dialog.
the code is already in the process of handling an action (onload) so i can't fire
the javascript from a button click or anything. i need to fire the javascript and
get the return value from the function, so that the following c# code can choose
action a or b based on the result.
how can i do this? it's frustrating that i can call the javascript code to present
the dialog (by doing response.write() with the script) but it doesn't seem to be
possible to get the result value.
code here shows the basic outline of my loadpage() function with the unrelated
junk stripped out.
if ( ! ispostback ) {
if ( recordislocked() ) {
lockfields();
lockedmessage +"');</script>");
} else {
lockrecord();
11
dev bhagat - 12/09/06
</asp:content>
� report offensive content
12
engin dikici - 03/11/06
13
asim - 17/11/06
hi
thanks
regards
� report offensive content
14
vinod - 15/02/07
hi,
i have html server control with required field validator and it was working fine
when i click on save button.
now i have added the onclientclick="return confrim('are your sure');" with save
button, and conform dialog box is working fine but the required fields validator
with the html controls are by passed and not working.
thanks
vinod
� report offensive content
15
charles - 28/02/07
16
krishna agrawal - 02/04/07
17
david - 18/05/07
18
kuldeep - 14/06/07
no thanks
19
deepak - 13/08/07
20
deepak - 13/08/07
give me code for opening a form in diffrent style
� report offensive content
21
deepak - 13/08/07
22
meenu - 05/09/07
i have to call a html page using the javascript in the specified portion of the
page without using frames.
� report offensive content
23
sumiya - 13/12/07