首页 > 代码库 > 页面单击按钮弹出modaldialog然后调用ajax处理程序获取数据,给父级页面控件赋值
页面单击按钮弹出modaldialog然后调用ajax处理程序获取数据,给父级页面控件赋值
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RefTopicList.aspx.cs" Inherits="Project.RefTopicList" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <base target="_self" /> <script src=http://www.mamicode.com/"../jquery/jquery-1.8.0.min.js" type="text/javascript"></script> <script type="text/javascript"> function Change(SCHeckBox, curHidOID) { var objs = document.getElementsByTagName("input"); for (var i = 0; i < objs.length; i++) { if (objs[i].type.toLowerCase() == "checkbox") objs[i].checked = false; } var SelectCheckBoxID = SCHeckBox.id; document.getElementById(SelectCheckBoxID).checked = true; $("#hidenOIDValue").val(curHidOID); } function GetHidValue() { if ($("#hidenOIDValue").val() != "") { returnValue = $("#hidenOIDValue").val(); window.close(); } else { alert(‘至少选择一项‘); } } </script></head><body> <form id="form1" runat="server"> <div> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td class="tb_td_content"> <asp:Button ID="QueryWatch" runat="server" Text=" 查 询 " OnClick="QueryWatch_Click" /> <input id="btnSure" type="button" value=http://www.mamicode.com/" 确 定 " onclick="GetHidValue();" /> </td> </tr> </table> </div> <div id="DivGridview"> <asp:GridView ID="CtrlGrid" runat="server" Width="80%" AllowSorting="True" CellPadding="0" BorderWidth="1px" BorderStyle="Solid" AutoGenerateColumns="False" OnRowDataBound="CtrlGrid_RowDataBound" PageSize="10" Height="128px"> <Columns> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <asp:HiddenField runat="server" ID="hidenCheckOID" Value=http://www.mamicode.com/‘<%#Eval("ID") %>‘ /> <asp:CheckBox runat="server" ID="chkSelect" /> </ItemTemplate> <HeaderStyle Wrap="False" Width="60px" HorizontalAlign="Center" /> <ItemStyle Wrap="false" Width="60px" HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField HeaderText="名称"> <ItemTemplate> <asp:Label ID="lblTopicName" runat="server" Text=‘<%# Eval("NAME")%>‘></asp:Label> </ItemTemplate> <HeaderStyle Wrap="false" Width="100px" HorizontalAlign="Center" /> <ItemStyle Wrap="false" Width="150px" HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView> </div> <asp:HiddenField ID="hidenOIDValue" runat="server" /> </form></body></html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditProjectInfo.aspx.cs" Inherits="EditProjectInfo" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <link href=http://www.mamicode.com/"../../Themes/Default/control.css" rel="stylesheet" type="text/css" /> <link href=http://www.mamicode.com/"../../Themes/Default/ui.css" rel="stylesheet" type="text/css" /> <script src=http://www.mamicode.com/"../../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script> <script src=http://www.mamicode.com/"../../Scripts/jquery/jquery-1.8.0.min.js" type="text/javascript"></script> <script src=http://www.mamicode.com/"../../Scripts/Validate/ControlValidate.js" type="text/javascript"></script> <link href=http://www.mamicode.com/"../../Themes/Default/controlvalidate.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function () { var typevalue=http://www.mamicode.com/<%=base.GetParaValue("type") %>; //后台传值判断是添加还是编辑 //0代表是编辑,页面上的选择按钮隐藏 if (typevalue =http://www.mamicode.com/= "0") { $("#btnSelect").hide(); } else{ //单击选择按钮弹出要选择的信息,选中之后在该页面获取该信息 $("#btnSelect").click(function () { var oidd = window.showModalDialog(‘RefTopicList.aspx‘,"", ‘dialogWidth=900px;dialogHeight=650px;help=no;location=no;scroll=no;resizable=no‘); if (oidd != undefined && oidd != "") { GetTopicJson(oidd); //调用处理程序的方法,用json解析获取数据 } }); } }); function GetTopicJson(oid) { $.ajax({ type: "post", url: "HandlerRefTipic.ashx?OID="+oid , dataType: "json", success: function (data) { $("#txtprojectName").val(data[0].TOPIC_NAME); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); } </script></head><body> <form id="form1" runat="server"><div class="datagrid_search_div"> <table class="tb" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="tb_td_title"> 项目名称: </td> <td class="tb_td_content" colspan="3" valign="top"> <asp:TextBox ID="txtprojectName" runat="server" Width="500px" request="true" MaxLength="100" CssClass="txtbox" ToolTip="项目名称,最多100个字符!"></asp:TextBox> <input id="btnSelect" type="button" value=http://www.mamicode.com/" 选 择 " class="btn_long" /> </td> </tr> <tr> <td colspan="4" class="tb_td_content" style="text-align: center;"> <asp:Button ID="btnSave" runat="server" class="btn_long" Text=" 保 存 " OnClick="btnSave_Click" /> <input id="btnReset" type="button" value=http://www.mamicode.com/" 重 置 " class="btn_long" runat="server" onclick="javascript:document.forms[0].reset();" /> <asp:Label ID="TipInfo" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label> </td> </tr> </table> </div></body></html>
<%@ WebHandler Language="C#" Class="HandlerRefTipic" %>using System;using System.Web;public class HandlerRefTipic : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "application/Json"; context.Response.Clear(); context.Response.Write(GetTopicToJson(context.Request["OID"])); context.Response.Flush(); context.Response.End(); } /// <summary> /// 根据标识得到课题对象实体转换成json格式输出 /// </summary> /// <param name="oid"></param> /// <returns></returns> public string GetTopicToJson(string oid) { if(string.IsNullOrEmpty(oid)) { return ""; } TopicInfoObj obj = new TopicInfoRepository().GetTopicInfoObj(oid); string str=new ConvertToJson().EntityToJson(obj); return str; } public bool IsReusable { get { return false; } }}
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {PageGridBind(); } } protected void CtrlGrid_RowDataBound(object sender, GridViewRowEventArgs e) { try { HiddenField hidenCheckID = (HiddenField)e.Row.FindControl("hidenCheckOID"); CheckBox checkBox = e.Row.FindControl("chkSelect") as CheckBox; checkBox.Attributes.Add("onclick", "Change(" + checkBox.ClientID + ",‘" + hidenCheckID.Value + "‘)"); base.ChangeRowColor(e); } catch (Exception ex) { throw ex; } } protected void PageGridBind() { GridView view = (GridView)this.FindControl("CtrlGrid"); if (view != null) { //DataTable dt=huoqushuju(); view.DataSource = dt; view.DataBind(); } } }
上面的js有的是我自己的样式文件,没有上传还有日历js都没有,大概就是这个思路,在第一个页面点击按钮然后弹出框,选中gridview中checkbox的,只能选择一行数据,获取到这行数据的id然后把这行数据通过json解析,然后再传到父级页面,给父级页面的控件赋值,就是这样一个思路,可以评论,吐槽,多多指正,谢谢!
页面单击按钮弹出modaldialog然后调用ajax处理程序获取数据,给父级页面控件赋值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。