动态生成按钮事件无法响应
private void LoadData(){
string condition = "43";
string tempstr = "<table cellpadding='0' cellspacing='0' border='0'>";
DataTable dt = dcpub.SelectAllTable("Courseware as cw left join CourseDetail as cd on cw.AutoID = cd.CourseID", "cw.AutoID = " + condition, "cw.AutoID as cwid,cd.AutoID as cdid,CourseName,CourseDesc,InteGral,TxtEn,TxtCn,SoundContent,cd.CreateDate ", "cdid desc");
if (dt.Rows.Count > 0)
{
div_Title.InnerHtml = "<h2>" + dt.Rows[0]["CourseName"].ToString() + "</h2>";
string lajici = "";
foreach (DataRow dr in dt.Rows)
{
lajici += dr["TxtEn"].ToString().Replace("'", "’") + "|";
}
//lajici = lajici.Replace("/(\s*?\r?\n\s*?)+/","\n");
int i = 1;
foreach (DataRow dr in dt.Rows)
{
string soundpath = "/CourseUploadFiles/MP3/" + dr["SoundContent"].ToString();
//lajici += dr["TxtEn"].ToString().Replace("'", "’") + "|";
tempstr += "<tr><td><a href=\"javascript:playthis('" + soundpath + "')\" style='cursor:pointer;'>英文:" + dr["TxtEn"].ToString()
+ "<br />中文:" + dr["TxtCn"] + "</a>"
+ "</td></tr>"
+ "<tr><td>"
+ "<input type=\"button\" value=\" 录音 \" id=\"btnRec_" + i + "\" name=\"btnRec_" + i + "\" onclick=\"Start_Rec('" + lajici + "')\" /> "
+ "<input type=\"button\" value=\" 停止录音 \" id=\"btnRecStop_" + i + "\" name=\"btnRecStop_" + i + "\" onclick=\"End_Rec('" + dr["TxtEn"].ToString().Replace("'", "’") + "')\" /> "
+ "<input type=\"button\" value=\" 回放 \" id=\"btnPlay_" + i + "\" name=\"btnPlay_" + i + "\" onclick=\"Listen_Rec()\" />"
+ " </td></tr>";
i++;
}
tempstr += "</table>";
//ClientScript.RegisterClientScriptBlock(GetType(), "Int_Rec", "<script>alert('111');</script>");
div_content.InnerHtml = tempstr;
}
}
生成控件后,无法调用前台JS方法。。无响应事件。。 --------------------编程问答-------------------- 把生成的html代码 贴一下 --------------------编程问答-------------------- 你这是客户端的BUTTON不是服务器端的,肯定可以执行JS代码,再仔细找找哪里错了 --------------------编程问答-------------------- 问题找出来了,
是因为dr["TxtEn"].ToString().Replace("'", "’") 读出来的时候在前台增加了"\n\r"导致前台页面换行。
谢谢上面2位了。。
补充:.NET技术 , ASP.NET