如何使用 runat = “server"在输入标签中? [英] How to use runat = "server" in input tag?

查看:25
本文介绍了如何使用 runat = “server"在输入标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 asp.net 编写.当我将 runat="server" 属性添加到我的输入标签时,它的值为空.当我删除 runat="server" 时,它可以正常工作.谁知道原因?

I'm writing in asp.net. When I add runat="server" property to my input tag, its value is null. When I remove runat="server" it works correctly. Who knows the reason?

我想从后面的代码中更改它的属性,这就是我编写 runat="server" 的原因.但是,该值为空.

I want change its property from code behind, that's why I wrote runat="server". However, the value is null.

protected void btnSaveChanges_Click(object sender, EventArgs e)
{
    string current_id = Session["Current_user"].ToString(); 
    string a = Request.Form["newusername"]; 
    string b = Request.Form["newpassword"]; 
    string c = Request.Form["rewpassword"];
}

控制代码:

<input type="text" name="newusername" placeholder="Enter Username" required="required" runat="server"/>

推荐答案

当你添加 runat="server" 并制作简单的 HTML 控件到 asp.net HTML 控件,然后 asp.net以不与同一页面上的其他 asp.net 控件冲突的方式呈现该控件的 idname.

When you add runat="server" and make the simple HTML control to asp.net HTML control, then asp.net renders the id and the name of that control in a manner that does not conflict with other asp.net controls on the same page.

因此将输入更改为:(注意现在我添加了id,并删除了name!)

So change the input to: (note now I add id, and remove the name!)

<input type="text" id="newusername" placeholder="Enter Username" required="required" runat="server"/>

并使用像这样的帖子获取值:

and get the value using the post like this:

Request.Form[newusername.UniqueID]

或使用值:

newusername.value

要考虑的其他链接:访问控制客户端名称而不是 IDASP.NET

这篇关于如何使用 runat = “server"在输入标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆