如何动态创建控件 我现在想实现在页面上点一下按钮就生成一个TextBox空间(可生成N个) 如何控制他们的ID? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用js生成input type='text',设置了name属性后,可以在提交时获得值 var tb = new TextBox();container.Controls.Add(tb); <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dynamicAdd.aspx.cs" Inherits="WebApp.dynamicAdd" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script type="text/javascript"> function addFile() { var div = document.createElement("div"); var f = document.createElement("input"); f.setAttribute("type", "text") f.setAttribute("name", "txtCardNo") f.setAttribute("size", "20") div.appendChild(f) var d = document.createElement("input"); d.setAttribute("type", "button") d.setAttribute("onclick", "deteFile(this)"); d.setAttribute("value", "移除") div.appendChild(d) document.getElementById("_container").appendChild(div); } function deteFile(o) { while (o.tagName != "DIV") o = o.parentNode; o.parentNode.removeChild(o); } </script></head><body> <form id="form1" runat="server"> <input value="add" type="button" onclick="addFile()" /> <div id="_container"> </div> <input type="submit" value="ok" /> </form></body></html>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace WebApp { public partial class dynamicAdd : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (string.IsNullOrEmpty(Request["txtCardNo"])) { string[] strCardes = Request["txtCardNo"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (string strCard in strCardes) { //to do } } } } }} 用js创建然后用request.form接收 生成客户端的,还是服务器端的呢?客户端的就好办多了.直接接接string串输出就行了. 在page_Lode会报错 - - 如果用服务器控件 那就在服务端new TextBox 就行了用html 控件 就用js 或jquery 动态生成html标记和设置id就行了。 给控件设置个name属性,后台获取用string name=Request["ControlName"] 麻烦看看,第三方控件怎么写成用户自定义控件。 跪求 这个构造方法,啥意思??? 求解Application_Start 过年了...没分了,但是我还是要送分给大家啊!没有目的!! String.Format什么意思啊 ? asp.net中如何向access数据库中插入日期类型数据[插入的数据为变量]? 急!!急!!急!!急!!急!!急!!100分在线等!! 怎样设置焦点? 如何实现上传一张大的图片,同时生成一张小的图片? gridview鼠标停留行进入编辑状态,离开这一行自动更新保存数据 .NET读取一个文件夹里面所有文件夹并且包括其子文件名称和其他的相关信息,可以做吗?
container.Controls.Add(tb);
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function addFile() {
var div = document.createElement("div");
var f = document.createElement("input");
f.setAttribute("type", "text")
f.setAttribute("name", "txtCardNo")
f.setAttribute("size", "20")
div.appendChild(f)
var d = document.createElement("input");
d.setAttribute("type", "button")
d.setAttribute("onclick", "deteFile(this)");
d.setAttribute("value", "移除")
div.appendChild(d)
document.getElementById("_container").appendChild(div);
} function deteFile(o) {
while (o.tagName != "DIV") o = o.parentNode;
o.parentNode.removeChild(o);
}
</script></head>
<body>
<form id="form1" runat="server">
<input value="add" type="button" onclick="addFile()" />
<div id="_container">
</div>
<input type="submit" value="ok" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApp {
public partial class dynamicAdd : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
if (string.IsNullOrEmpty(Request["txtCardNo"])) {
string[] strCardes = Request["txtCardNo"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string strCard in strCardes) {
//to do
}
}
}
}
}
}
然后用request.form接收
在page_Lode会报错 - -