动态生成的BUTTON事件为什么要点击两次才能执行到?

chinascprogram 2008-03-07 11:07:55
动态生成的BUTTON事件为什么要点击两次才能执行到?
...全文
154 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinascprogram 2008-03-07
  • 打赏
  • 举报
回复
5 楼的QQ号多少,加一个?我的12019708
aa11582283 2008-03-07
  • 打赏
  • 举报
回复
没遇到过 需要看下你代码
cefriend 2008-03-07
  • 打赏
  • 举报
回复
页面看加过ispostback
chinascprogram 2008-03-07
  • 打赏
  • 举报
回复
我是做的是可连续上传文件并动态显示出来,帮忙看看!
chinascprogram 2008-03-07
  • 打赏
  • 举报
回复
/// <summary>
/// 显示已上传文件
/// </summary>
private void BuildFileList()
{
string StrFilePath = this.HidPath.Value.ToString();
string StrFileShowName = this.HidShowName.Value.ToString();
string StrUpTime = this.HidUptime.Value.ToString();

/// <summary>
/// 上传文件属性多维数组
/// </summary>
string[,] GetUploadArray = new string[20,3];

///取相对路径存入多维数组
string[] FilePathArray = StrFilePath.Split(',');
for (int i = 0; i < FilePathArray.Length; i++)
{
GetUploadArray[i, 0] = FilePathArray[i];
}

///取显示名称存入多维数组
string[] FileShowNameArray = StrFileShowName.Split(',');
for (int j = 0; j < FileShowNameArray.Length; j++)
{
GetUploadArray[j, 1] = FileShowNameArray[j];
}

///取上传时间存入多维数组
string[] FileUpTimeArray = StrUpTime.Split(',');
for (int n = 0; n < FileUpTimeArray.Length; n++)
{
GetUploadArray[n, 2] = FileUpTimeArray[n];
}

///文件信息输出
if (FilePathArray.Length >=1 & FilePathArray[0] != "")
{
Panel1.Controls.Clear();
for (int m = 0; m < FilePathArray.Length; m++)
{
Table Table = new Table();
Table.CellSpacing = 0;
Table.CellPadding = 0;
Table.BorderWidth = 1;
Table.Width = 500;
Table.BorderStyle = BorderStyle.Groove;

TableRow tr = new TableRow();
Table.Rows.Add(tr);
tr.Height = 25;
tr.Font.Bold = true;
tr.HorizontalAlign = HorizontalAlign.Center;
TableCell td1 = new TableCell();
TableCell td2 = new TableCell();
TableCell td3 = new TableCell();
td1.Width = 300;
td2.Width = 120;
td3.Width = 80;

tr.Cells.Add(td1);
tr.Cells.Add(td2);
tr.Cells.Add(td3);

LinkButton Lbtn = new LinkButton();
Lbtn.ID = "LinkBtn" + m;
Lbtn.Text = GetUploadArray[m, 1].ToString();
Lbtn.PostBackUrl = GetUploadArray[m, 0].ToString();
Lbtn.ToolTip = GetUploadArray[m, 0].ToString();
Lbtn.CausesValidation = false;
td1.Controls.Add(Lbtn);

Label LabTime = new Label();
LabTime.ID = "Lable" + m;
LabTime.Text = GetUploadArray[m, 2].ToString();
td2.Controls.Add(LabTime);

Button BtnDel = new Button();
BtnDel.Text = "移除文件";
BtnDel.Height= 20;
BtnDel.CommandName = GetUploadArray[m, 0].ToString() + "," + GetUploadArray[m, 1].ToString() + "," + GetUploadArray[m, 2].ToString();
BtnDel.Command += new CommandEventHandler(BtnDel_Command);
td3.Controls.Add(BtnDel);
this.Panel1.Controls.Add(Table);
}
}
}


/// <summary>
/// 删除文件并将保留文件值赋予隐藏域
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void BtnDel_Command(object sender, CommandEventArgs e)
{
this.Panel1.Controls.Clear();
string[] ArrayPath = e.CommandName.ToString().Split(',');
string PathArray = Server.MapPath(ArrayPath[0].ToString());

string HideenFilePath = this.HidPath.Value.ToString();
string HideenFileShowName = this.HidShowName.Value.ToString();
string HideenFileUplodTime = this.HidUptime.Value.ToString();

string[] PathArray = HideenFilePath.Split(',');
string[] ShowNameArray = HideenFileShowName.Split(',');
string[] UptimArray = HideenFileUplodTime.Split(',');

///设置移除文件后保留的文件集路径
if (PathArray.Length > 1 & PathArray[0].ToString() != ArrayPath[0].ToString())
{
this.HidPath.Value = HideenFilePath.Replace("," + ArrayPath[0].ToString(), "");
}
else
{
this.HidPath.Value = HideenFilePath.Replace(ArrayPath[0].ToString(), "");
}

///设置移除文件后保留的文件原名称
if (ShowNameArray.Length > 1 & ShowNameArray[0].ToString() != ArrayPath[1].ToString())
{
this.HidShowName.Value = HideenFileShowName.Replace("," + ArrayPath[1].ToString(), "");
}
else
{
this.HidShowName.Value = HideenFileShowName.Replace(ArrayPath[1].ToString(), "");
}

///设置移除文件后保留的文件上传时间
if (UptimArray.Length > 1 & UptimArray[0].ToString() != ArrayPath[2].ToString())
{
this.HidUptime.Value = HideenFileUplodTime.Replace("," + ArrayPath[2].ToString(), "");
}
else
{
this.HidUptime.Value = HideenFileUplodTime.Replace(ArrayPath[2].ToString(), "");
}

///删除选择移除的文件
if (System.IO.File.Exists(PathArray))
{
System.IO.File.Delete(PathArray);
}
this.Panel1.Controls.Clear();
this.BuildFileList();
}
zhuanshen712 2008-03-07
  • 打赏
  • 举报
回复
把你代码弄出来看看。
chinascprogram 2008-03-07
  • 打赏
  • 举报
回复
有谁碰到过?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧