asp.net每点一次按钮添加一个控件怎么实现?
代码如下:为什么不能实现呢?Global文件有Session了!protectedvoidBtadd_Click(objectsender,EventArgse){int...
代码如下:为什么不能实现呢?Global文件有Session了!
protected void Btadd_Click(object sender, EventArgs e)
{
int i = (int)Session["count"];
i++;
FileUpload ful = new FileUpload();
ful.ID ="f" + i.ToString();
Panel1.Controls.Add(ful);
Session["count"] = i; 展开
protected void Btadd_Click(object sender, EventArgs e)
{
int i = (int)Session["count"];
i++;
FileUpload ful = new FileUpload();
ful.ID ="f" + i.ToString();
Panel1.Controls.Add(ful);
Session["count"] = i; 展开
1个回答
展开全部
用JS实现即可,这里实现的是HTML的FILE控件,可以类似实现ASP.NET的WEB控件FileUpload
<script language="javascript" type="text/javascript">
//增加文件上传控件
function AddFileUpload()
{
var str = '<span><br/><input type="file" unselectable="on" onchange="return CheckFile(this)"/> <input type="button" value="删除" onclick="deleteNode(this.parentNode)"></span>'; document.getElementById("UploadDiv").insertAdjacentHTML("beforeEnd",str);
}
//删除结点
function deleteNode(obj)
{
obj.removeNode(true);
}
</script>
<center>
<div id="UploadDiv">
<span id="UploadSpan">
<input id="FileUpload" type="file" unselectable="on" onchange="return CheckFile(this);"/>
</span>
</div>
</center>
<p>
<center>
<input type="button" value="增行" onclick="AddFileUpload()" /><br />
</center>
</p>
<script language="javascript" type="text/javascript">
//增加文件上传控件
function AddFileUpload()
{
var str = '<span><br/><input type="file" unselectable="on" onchange="return CheckFile(this)"/> <input type="button" value="删除" onclick="deleteNode(this.parentNode)"></span>'; document.getElementById("UploadDiv").insertAdjacentHTML("beforeEnd",str);
}
//删除结点
function deleteNode(obj)
{
obj.removeNode(true);
}
</script>
<center>
<div id="UploadDiv">
<span id="UploadSpan">
<input id="FileUpload" type="file" unselectable="on" onchange="return CheckFile(this);"/>
</span>
</div>
</center>
<p>
<center>
<input type="button" value="增行" onclick="AddFileUpload()" /><br />
</center>
</p>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询