主题:[讨论]想实现像163邮箱中附件上传框的动态生成和删除
我想做一个附件上传,像163邮箱中那样每点击一次"添加附件"按钮页面上增加一个附件上传和"删除"按钮,若是点击"删除"按钮则对应的附件上传框和"删除"按纽同时消失.
我的想法是:在Web用户控件中放置一个Panel,里面有一个FileUpload和一个button(删除)按钮.点击"删除"按钮时移除此Panel.Web用户控件被动态引用到页面中.相关代码如下:
主页面代码是:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebSite7_Test1 : System.Web.UI.Page
{
protected Control uc1;
protected void Page_Load(object sender, EventArgs e)
{
int a = Convert.ToInt16(ViewState["Count"]);
int b = Convert.ToInt16(ViewState["num"]);
int count =a-b;
for (int i = 0; i < count; i++)
{
uc1 = LoadControl("WebUserControl.ascx");
Panel1.Controls.Add(uc1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
uc1 = LoadControl("WebUserControl.ascx");
Panel1.Controls.Add(uc1);
ViewState["Count"] = Convert.ToInt16(ViewState["Count"]) + 1;
}
}
Web用户控件中:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebSite7_WebUserControl : System.Web.UI.UserControl
{
protected void Button1_Click(object sender, EventArgs e)
{
this.Controls.Remove(Panel1);
ViewState["num"] = Convert.ToInt16(ViewState["num"]) + 1;
}
}
结果实现有问题,请大家帮忙出出主意,或许思路上有问题
我的想法是:在Web用户控件中放置一个Panel,里面有一个FileUpload和一个button(删除)按钮.点击"删除"按钮时移除此Panel.Web用户控件被动态引用到页面中.相关代码如下:
主页面代码是:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebSite7_Test1 : System.Web.UI.Page
{
protected Control uc1;
protected void Page_Load(object sender, EventArgs e)
{
int a = Convert.ToInt16(ViewState["Count"]);
int b = Convert.ToInt16(ViewState["num"]);
int count =a-b;
for (int i = 0; i < count; i++)
{
uc1 = LoadControl("WebUserControl.ascx");
Panel1.Controls.Add(uc1);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
uc1 = LoadControl("WebUserControl.ascx");
Panel1.Controls.Add(uc1);
ViewState["Count"] = Convert.ToInt16(ViewState["Count"]) + 1;
}
}
Web用户控件中:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebSite7_WebUserControl : System.Web.UI.UserControl
{
protected void Button1_Click(object sender, EventArgs e)
{
this.Controls.Remove(Panel1);
ViewState["num"] = Convert.ToInt16(ViewState["num"]) + 1;
}
}
结果实现有问题,请大家帮忙出出主意,或许思路上有问题