views:

23

answers:

2

hi all i want to know that can we validate a control which is out side a form element in asp.net(server side validation)and outside a form element in html(client side validation) let's take a closer look

<html>
<body>
<input type="text"  name="first name"/>
</body>
</html>

can we apply clien side validation on above text box by java script ?

in asp.net

<form runat="server">
</form>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

here i have written textbox after the form will it validate at server side ?

A: 

Sure, if you set the input to runat the server and give it an ID:

<input type="text"  name="first name" runat="server" id="myserversideid"/>

You can then use the validation controls as you would normally

m.edmondson
i am talking about 2nd on i means asp.net not on html ?
Nishant
first read question carefully then give answer ?
Nishant
acording to you if i write any asp contro out side form then it will not run on server ?
Nishant
Unless anyone can prove me wrong?
m.edmondson
+2  A: 

Last time I checked, it wasn't valid HTML to have form elements, such as inputs, outside a form.

In any case, it won't work on the server-side because ASP.NET does not know the textbox exists. I could see it working client-side, but I have never tried this as it makes no sense.

What are you trying to achieve here? There is likely a better solution.

Wyatt Barnett
but sir it's working well in any browser ? i means when we apply only client side validation then need not necessary to keep it inside form afterall i am not sending data on server side for validation ?
Nishant
thank's sir really it's not working ?
Nishant