简体   繁体   English

ASP.NET中的HTML表单

[英]HTML forms in ASP.NET

Hello all how to use HTML text field instead of ASP.NET textbox.? 您好,所有如何使用HTML文本字段而不是ASP.NET文本框。

How to write C# code to make use of HTML forms instead of ASP.NET 如何编写C#代码以使用HTML表单而不是ASP.NET

Instead of using or whatever server control, just type in the standard type tags or whichever HTML control you want. 无需使用或使用任何服务器控件,只需键入标准类型标签或所需的任何HTML控件即可。

If you want to be able to access them from your code-behind, then just include a runat="server" value with each HTML tag and make sure you give it an ID. 如果您希望能够从背后的代码中访问它们,则只需在每个HTML标记中包含runat =“ server”值,并确保为其提供ID。

You need to retrieve the value from the HTTP request's Form collection: 您需要从HTTP请求的Form集合中检索值:

<input type="text" name="MyTextField" />

Code behind: 后面的代码:

string value = Request.Form["MyTextField"];

This question doesn't make much sense. 这个问题没有多大意义。 You really should clarify and flesh out the question and explain what you are trying to do. 您确实应该澄清并充实问题,并解释您要做什么。

In some ways, an ASP.NET textbox is an HTML text field that C# code can make use of. 在某些方面,ASP.NET文本框 C#代码可以利用的HTML文本字段。 So what's the problem with an ASP.NET textbox? 那么,ASP.NET文本框有什么问题?

You can create an instance of a HtmlInput control in code, or alternatively add a runat="server" attribute to an <input> element in your aspx file, you can then access this from server-side code using it's ID. 您可以在代码中创建HtmlInput控件的实例,或者将runat =“ server”属性添加到aspx文件中的<input>元素,然后可以使用其ID从服务器端代码访问此属性。

As an alternative, you may wish to take a look at http://asp.net/mvc to get better control of your HTML markup. 另外,您可能希望看看http://asp.net/mvc,以更好地控制HTML标记。

EDIT: 编辑:

<form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <input id="Text1" type="text" runat="server" />

    <asp:Button ID="Button5"
        runat="server" Text="Button" OnClick="button5_click" />
    <div>


        <script runat="server">
            protected void button5_click(object sender, EventArgs e)
            {
                Text1.Value = "Hello";
            }
        </script>


</form>

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

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