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?
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()
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();
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.
精彩评论