3

i have an asp.net webform. the users enter data into the textboxes and i do OnClick="SubmitData" with a button:

now i would like to use jquery and make my form look much better and i do not know if i can keep the asp.net controls or whether i have to convert to html controls.

question do i need to convert

<asp:TextBox ID="section_c_issue_error_identified_byTextBox"  width="500" runat="server" 
                    />

to something like this:

<textarea name="comments" id="comments" rows="5" cols="60"></textarea>

and if so, how would i grab the user input from these new html textboxes?

can you tell me exactly how would i pass these values into my c# code?

3 Answers 3

5

You don't need to convert anything as it gets converted to html anyway on clientside.

There are few ways to grab the value of the text box such as,

If the following is my textbox,

   <asp:TextBox ID="txtCountry" Width="500" runat="server" CssClass="countryText" />

I can use,

$('#<%= txtCountry.ClientID%>').val()

$('.countryText').val()
Sign up to request clarification or add additional context in comments.

Comments

2

You don't need to convert anything, simply adding the property clientID the type static

 ClientIDMode="Static"

That's warranted that the id asp component doesn't change the name of the id

<asp:TextBox ID="txtCountry" Width="500" runat="server" CssClass="countryText"  ClientIDMode="Static" />

$('#txtCountry').val();   

2 Comments

Correction: $('#txtCountry').val(); By the way, while static clientmode is another option I guess it should only be used in very special cases or else it may end up leaving your code base too restricted.
unless hes not using aspnet 4
0

question do i need to convert

<asp:TextBox ID="section_c_issue_error_identified_byTextBox" 

width="500" runat="server" />

to something like this:

<textarea name="comments" id="comments" rows="5"

cols="60">

Yes, you need to do that.

To capture input from those controls using JQuery, you need to do:

var elementValue = $('#elementid').val();

elementid is the id you assigned to the element in your markup. In your example above, it would be "comments".

elementValue will have the text entered in your text area.

2 Comments

thanks so much again for willing to help me. can you tell me exactly how would i pass these values into my c# code? im sorry i am an asp.net beginner. also where woudl i put the var elementvalue?
do you want to use jquery and still submit and process the form via server side code? If so, you can still add the tag runat="server" and aspnet will let you "see" those controls server side. If you just want to style the controls using jquery, or any javascript code, you don't HAVE to change the controls, because ASPNET will generate html code anyway. Take a look at the source of the page once in the browser and you will see all of the html.

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.