简体   繁体   English

“将”asp.net表单转换为html表单

[英]“Converting” asp.net form to html form

i have an asp.net webform. 我有一个asp.net webform。 the users enter data into the textboxes and i do OnClick="SubmitData" with a button: 用户将数据输入文本框,然后使用按钮执行OnClick="SubmitData"

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. 现在我想使用jquery并使我的表单看起来更好,我不知道我是否可以保持asp.net控件或我是否必须转换为HTML控件。

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? 如果是这样,我将如何从这些新的html文本框中获取用户输入?

can you tell me exactly how would i pass these values into my c# code? 你能告诉我到底如何将这些值传递给我的c#代码?

You don't need to convert anything as it gets converted to html anyway on clientside. 您无需转换任何内容,因为它在客户端无论如何都会转换为html。

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 您不需要转换任何内容,只需添加属性clientID类型为static

 ClientIDMode="Static"

That's warranted that the id asp component doesn't change the name of the id 这是有理由的,id asp component不会更改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" /> width =“500”runat =“server”/>

to something like this: 这样的事情:

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

cols="60"> COLS = “60”>

Yes, you need to do that. 是的,你需要这样做。

To capture input from those controls using JQuery, you need to do: 要使用JQuery从这些控件捕获输入,您需要执行以下操作:

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

elementid is the id you assigned to the element in your markup. elementid是您为标记中的元素指定的ID。 In your example above, it would be "comments". 在上面的例子中,它将是“评论”。

elementValue will have the text entered in your text area. elementValue将在您的文本区域中输入文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM