【发布时间】:2023-03-26 16:51:01
【问题描述】:
谁能帮我解决这个代码:
平均售价:
<script type="text/javascript">
function confirm_delete(div.ID)// problem here{
if (confirm('Are you sure you want to delete?')) {
__doPostBack('DivClicked', div.ID);
// not sure if javascript will pick up on the string from server side code
}
else {
return false;
}
}
页面加载代码后面:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//It is a postback so check if it was by div click
string target = Request["__EVENTTARGET"];
if (target == "DivClicked")
{
String.Format(div.ID) = Request["__EVENTARGUMENT"];
// problem converting div.ID from Javascript to string (because of the dot)
Response.Write(String.Format(div.ID));
// same problem here
}
}
string theUserId = Session["UserID"].ToString();
PopulateWallPosts(theUserId);
}
代码背后:
while (reader.Read())
{
System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
div.Attributes["class"] = "test";
div.ID = String.Format("{0}", reader.GetString(0));
Convert.ToString(div.ID);
//store the div id as a string
Image img = new Image();
img.ImageUrl = String.Format("{0}", reader.GetString(2));
img.AlternateText = "Test image";
div.Controls.Add(img);
div.Controls.Add(ParseControl(String.Format("   " + "{0}", reader.GetString(1))));
div.Attributes.Add("onclick", "return confirm_delete(" + div.ID + ");");
// send the div id to javascript, not sure this line will work
div.Style["clear"] = "both";
test1.Controls.Add(div);
}
}
}
}
}
【问题讨论】:
标签: c# javascript asp.net html