在网上查了一些资料用于window.showModalDialog返回值,并用于项目中,下面是代码:
<script language="javascript" type="text/javascript"> function OpenWin(id) { var temp=window.showModalDialog("/test.aspx?ID=" + id + "&DT=" + new Date(), window, "dialogWidth:1020px;dialogHeight:700px;scroll:auto;status:no;help:no;"); if (temp === undefined) { return false; } temp = $.parseJSON(temp); if (temp.Action == "delete") { if (anSelected.length !== 0) { alert("delete"); oTable.fnDeleteRow(anSelected[0]); } } else if (temp.Action == "update") { var content = unescape(temp.Content); $("TD", $(content)).each(function (i) { if (i == 0) { return; } var tdHTML = $(this).html(); $("TD", anSelected).eq(i).html(tdHTML); }); } } </script>
下面是test页面的代码,关闭窗体的代码,一般会在后台注册
<script type="text/javascript"> function closeWindow(action, content) { //var arr = new Array(2); //arr[0] = action; //arr[1] = "<td>Record Number</td><td>Detail Description</td><td> Wave</td><td>Visite Ref.访谈场次 </td> <td>Date访谈日期</td><td> Function类别</td><td>ProgrameProject 项目</td><td>类别II</td><td>建议类型</td><td>状态</td><td> 创建者</td>"; //arr[1] = content //window.returnValue = "{\"Action\":\"" + arr[0] + "\",\"Content\":\"" + escape(arr[1]) + "\"}"; window.returnValue = "{\"Action\":\"" + action + "\",\"Content\":\"" + escape(content) + "\"}" window.close(); } </script> <base target="_self" />
在后台注册比较长的字符串中要注册一些特殊的字符,下面是后台的一些过滤源代码
private string GetModifiedMessage(SPListItem item) { StringBuilder sb = new StringBuilder(); sb.Append("<tr>"); sb.Append("<td><input type=\"checkbox\" name=\"chk\" value=\"" + ConvertNULL(item["ID"]) + "\" />" + "</td>"); if (string.IsNullOrEmpty(ConvertNULL(item["RecordNumber"]))) { sb.Append("<td>" + ConvertNULL(item["RecordNumber"]) + "</td>"); } else { sb.Append("<td>" + ConvertNULL(item["RecordNumber"]).Split('#')[1]+ "</td>"); } sb.Append("<td>" + ConvertNULL(item["IssueDetail"])+ "</td>"); sb.Append("<td>" + ConvertNULL(item["场次"]) + "</td>"); sb.Append("<td>" + ConvertNULL(item["Date"]) + "</td>"); sb.Append("<td>" + GetShortCode(ConvertNULL(item["Category1"])) + " " + ConvertNULL(item["类别一"]) + "</td>"); sb.Append("<td>" + GetShortCode(ConvertNULL(item["Category2"])) + " " + ConvertNULL(item["类别二"]) + "</td>"); sb.Append("<td>" + GetShortCode(ConvertNULL(item["Category3"])) + " " + ConvertNULL(item["类别三"]) + "</td>"); sb.Append("<td>" + GetShortCode(ConvertNULL(item["Category4"])) + " " + ConvertNULL(item["类别四"]) + "</td>"); sb.Append("<td>" + ConvertNULL(item["Status"]) + "</td>"); sb.Append("<td>" + ConvertNULL(item["Author"]).Split('#')[1]+ "</td>"); //sb.Append("<td>" + "<input type=\"button\" value=\"Confirm\" onclick=\"OpenWin(" + ConvertNULL(item["ID"]) + ")\" class=\"bnA\" /></td>"); sb.Append("</tr>"); return sb.ToString().Replace("<br/>", string.Empty).Replace("\r", "\\n").Replace("\n", "\\n").Replace("'","\'"); }
后台引用的代码:
ClientScript.RegisterStartupScript(this.GetType(), "close", string.Format("closeWindow('delete','{0}');", GetModifiedMessage(item)), true);