0

Can anyone help?

I normally use server controls i.e Textbox so i can get access to the server side event.

But what if i don't need access to the server side event and i am going to place some jquery or javascript on the textbox for example.

Can i use a standard HTML (client controls) ?

Is this good practice or not?

Thanks in advance

3 Answers 3

2

YOu can use simple HTML standard control BUT if you want to access that controls value in ASP.NET then you will have to add runat="server tag" see below

<input type="text" runat="server" id="mytxtbox" name="mytxtbox">

If you really want to use HTML controls you can use them. but it will make your life easy to use standard ASP.NET controls if you are trying to access them on server side.

And if you want to access those controls using javascript as well then you can use something like

var mytxtele = document.getElementById('<%= mytxtbox.ClientID %>')

thats how you can get textbox element and play with it in javascript.

This above code is a basic idea, depends how you want it to work

Sign up to request clarification or add additional context in comments.

1 Comment

+1. It is a fine practice to use standard HTML input fields if they need not be accessed from your C#/VB. In fact, it probably reduces server processing time, if you want to split hairs.
1

1)If the controls are not going to be accessed in the server side, avoid using server controls.

2)When a server control is used, it goes through the whole life cycle starting from initialization to rendering and finally unloading.

3)It also saves the memory constraint on the view state.

Comments

0

Yes you can use standard HTML controls, but asp.net controls are more flexible and you will have the same html output for each control types. If you need to use JQuery and you have problems with controls IDs, see the documentation because you can write something like this (suppose JQuery in asp.net tag):

$('#<%=this.clientId%>').style.display = 'block';

Anyway, I'm sure that there is a method in JQuery to call a single object also when know only a part of his ID name (but I don't remember how.. :))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.