asp.net父子页面弹出与传值问题!重赏!

玉凌风_BLOG 2008-12-11 10:57:53
我想用asp.net实现像这个网站(http://searchjob.chinahr.com/)一样单击文本框弹出一个子页面(在这个页面中单击“职位类别”输入框可看到),然后在子页面中选择某个“checkBox” 单击“确定”,该checkBox的值就传到了父页面的输入框中,同时关闭子页面。
我现在用语句 Label7.Attributes.Add("onclick","window.showModalDialog('add_class.aspx')")添加Label7的鼠标单击事件,弹出“add_class.aspx”页面。
谁能帮我实现上面那个网站上一模一样的功能啊。
要源代码!尽量不要超出asp.net的范围。我的前台是“.aspx”页面,后台是“.aspx.cs”的文件。
谢谢!
...全文
1033 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
玉凌风_BLOG 2008-12-14
  • 打赏
  • 举报
回复
谢谢 hmily821023 的提示,我使用了弹层,果然简单很多,而且就是我所要的结果。
也谢谢大家的回答!
问题已经解决!
  • 打赏
  • 举报
回复
js + div做的

背景 一个div 满屏 设置透明度

前面显示一个div 设置z-index 大于背景的
Norris Huang 2008-12-12
  • 打赏
  • 举报
回复
JS中用 var parwin = window.dialogArguments; 获取父窗口的对象,然后操作parwin中的控件
yefengzhixia 2008-12-12
  • 打赏
  • 举报
回复
顶了

刚开了一新的c#群 63242231 希望有志同道合的 朋友加入 更期望高手的加入

有您的加入会更精彩。。。
txl816 2008-12-12
  • 打赏
  • 举报
回复
传父 用parent
sportdog 2008-12-12
  • 打赏
  • 举报
回复
我是在父页面上有个按钮,点击按钮弹出用户列表,再双击用户列表中的记录,把用户code填到父页面的文本框中。

注:我在子页面加载时已经把checkme函数绑定到每条记录的双击事件上了,里面的参数也绑好了。
后台代码
foreach (GridViewRow gvr in this.gvBuyer.Rows)
{
gvr.Attributes.Add("ondblclick", "CheckMe('"+gvr.Cells[0].Text.Trim()+"')");
}

你看看,是否和我的情况类似。
sportdog 2008-12-12
  • 打赏
  • 举报
回复
晕,星星贴的代码也太长了吧,不用这么麻烦吧 .


父页面
点击按钮调用以下js函数
function OpenBuyerPage(id)
{
window.showModalDialog("child.aspx?id="+id+"&temp="+Math.random(), window, "status:no;center:yes;help:no;minimize:no;maximize:no;border:thin;dialogWidth:800px; dialogHeight:500px");
}

child.aspx

function CheckMe(returnValue)
{
window.dialogArguments.document.all.txt1234.value = returnValue;
window.close();
}
白云任去留 2008-12-12
  • 打赏
  • 举报
回复
看下...
玉凌风_BLOG 2008-12-12
  • 打赏
  • 举报
回复
我用的工具是 vs2005,做的是asp.net网站。
谢谢大家的回答,你们的提示我会一个个尝试的
ChengKing 2008-12-11
  • 打赏
  • 举报
回复
只能分多次发. 看起来可能不大方便.
ChengKing 2008-12-11
  • 打赏
  • 举报
回复

/// <summary>
/// 注册客户端脚本
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
string strJSPath = base.ResolveUrl(Path.Combine(this.ClientPath, @"Js\RefrenceControl.js"));
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "RefControlJS"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RefControlJS",
"<script type='text/javascript' src='" + strJSPath + "'></script>", false);
}

}

//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("id", this.ClientID);
writer.AddAttribute("name", this.UniqueID);

string strClientClickMethod = "ClientRefClick();";

StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\">");


sb.AppendFormat(" window.{0} = new RefrenceControl('{0}');", this.ClientID);
sb.AppendFormat("{0}.BtnElementId = '{1}';", this.ClientID, this.btn.ClientID);
sb.AppendFormat("{0}.TxtElementId = '{1}';", this.ClientID, this.txt.ClientID);
sb.AppendFormat("{0}.HidElementId = '{1}';", this.ClientID, this.hid.ClientID);
sb.AppendFormat("{0}.DataSource = '{1}';", this.ClientID, this.DataSource.ToString());
sb.AppendFormat("{0}.RefPage = '{1}';", this.ClientID, this.RefPage.Replace("\\", "/"));
sb.AppendFormat("{0}.RefWhere = \"{1}\";", this.ClientID, this.RefWhere);
sb.AppendFormat("{0}.ClientClickMethod = \"{1}\";", this.ClientID, strClientClickMethod);
sb.AppendFormat("{0}.ClientAcceptValueMethod = '{1}';", this.ClientID, this.ClientAcceptValueMethod.Trim());
//启动脚本
sb.AppendFormat("window.{0}.Start();", this.ClientID);
sb.Append("</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "Start",
sb.ToString(), false);

if (this.Height != Unit.Empty)
{
writer.AddAttribute("Height", this.Height.ToString());
}
if (this.Width != Unit.Empty)
{
writer.AddAttribute("Width", this.Width.ToString());
}
txt.Width = this.Width;

writer.AddAttribute("cellspacing", "0");
writer.AddAttribute("cellpadding", "0");
writer.AddAttribute("scale", "1");
writer.AddStyleAttribute("display", "inline");
writer.AddStyleAttribute("vertical-align", "middle");
writer.AddStyleAttribute("position", "relative");

if (this.Enabled == false)
{
writer.AddAttribute("disabled", "true");
txt.Attributes.Add("disabled", "true");
}

writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);

if (this.EnableTextBox == true)
{
txt.ReadOnly = false;
txt.Style.Add("background-color", "#ffffff");
}
else
{
txt.ReadOnly = true;
txt.Style.Add("background-color", "#f4f4f4");
}
txt.Style.Add("Height", "100%");
txt.RenderControl(writer);

string strRefImageUrl = base.ResolveUrl( Path.Combine(this.ClientPath, @"Images\ref.jpg") );
btn.ImageUrl = strRefImageUrl;
btn.Style.Add(HtmlTextWriterStyle.Cursor, "hand");
btn.Style.Add(HtmlTextWriterStyle.Position, "absolute");
btn.Style.Add("right", "1px");
btn.Style.Add("top", "2px");
btn.Style.Add("z-index", "9999");
btn.Style.Add("float", "right");

if (this.EnableButton == false)
{
btn.Attributes.Add("disabled", "true");
}

writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);

btn.RenderControl(writer);
hid.RenderControl(writer);

writer.RenderEndTag(); //</TD>
writer.RenderEndTag(); //</TR>

writer.RenderEndTag();

}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public enum DataSourceType
{
/// <summary>
/// 往来单位
/// </summary>
Customer,

/// <summary>
/// 部门
/// </summary>
Department
}



上面是控件服务端代码.

在本书中有完整示例讲解.
《庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术》
--基于VS 2008(兼容VS 2005)C#。本书为Asp.net进阶教材,本书介绍及阅读链接如下:
http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx

近期会把五章控件开发内容发布到此链接. 可以供大家学习.
ChengKing 2008-12-11
  • 打赏
  • 举报
回复

/// <summary>
/// 注册客户端脚本
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
string strJSPath = base.ResolveUrl(Path.Combine(this.ClientPath, @"Js\RefrenceControl.js"));
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "RefControlJS"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RefControlJS",
"<script type='text/javascript' src='" + strJSPath + "'></script>", false);
}

}

//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("id", this.ClientID);
writer.AddAttribute("name", this.UniqueID);

string strClientClickMethod = "ClientRefClick();";

StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\">");


sb.AppendFormat(" window.{0} = new RefrenceControl('{0}');", this.ClientID);
sb.AppendFormat("{0}.BtnElementId = '{1}';", this.ClientID, this.btn.ClientID);
sb.AppendFormat("{0}.TxtElementId = '{1}';", this.ClientID, this.txt.ClientID);
sb.AppendFormat("{0}.HidElementId = '{1}';", this.ClientID, this.hid.ClientID);
sb.AppendFormat("{0}.DataSource = '{1}';", this.ClientID, this.DataSource.ToString());
sb.AppendFormat("{0}.RefPage = '{1}';", this.ClientID, this.RefPage.Replace("\\", "/"));
sb.AppendFormat("{0}.RefWhere = \"{1}\";", this.ClientID, this.RefWhere);
sb.AppendFormat("{0}.ClientClickMethod = \"{1}\";", this.ClientID, strClientClickMethod);
sb.AppendFormat("{0}.ClientAcceptValueMethod = '{1}';", this.ClientID, this.ClientAcceptValueMethod.Trim());
//启动脚本
sb.AppendFormat("window.{0}.Start();", this.ClientID);
sb.Append("</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "Start",
sb.ToString(), false);

if (this.Height != Unit.Empty)
{
writer.AddAttribute("Height", this.Height.ToString());
}
if (this.Width != Unit.Empty)
{
writer.AddAttribute("Width", this.Width.ToString());
}
txt.Width = this.Width;

writer.AddAttribute("cellspacing", "0");
writer.AddAttribute("cellpadding", "0");
writer.AddAttribute("scale", "1");
writer.AddStyleAttribute("display", "inline");
writer.AddStyleAttribute("vertical-align", "middle");
writer.AddStyleAttribute("position", "relative");

if (this.Enabled == false)
{
writer.AddAttribute("disabled", "true");
txt.Attributes.Add("disabled", "true");
}

writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);

if (this.EnableTextBox == true)
{
txt.ReadOnly = false;
txt.Style.Add("background-color", "#ffffff");
}
else
{
txt.ReadOnly = true;
txt.Style.Add("background-color", "#f4f4f4");
}
txt.Style.Add("Height", "100%");
txt.RenderControl(writer);

string strRefImageUrl = base.ResolveUrl( Path.Combine(this.ClientPath, @"Images\ref.jpg") );
btn.ImageUrl = strRefImageUrl;
btn.Style.Add(HtmlTextWriterStyle.Cursor, "hand");
btn.Style.Add(HtmlTextWriterStyle.Position, "absolute");
btn.Style.Add("right", "1px");
btn.Style.Add("top", "2px");
btn.Style.Add("z-index", "9999");
btn.Style.Add("float", "right");

if (this.EnableButton == false)
{
btn.Attributes.Add("disabled", "true");
}

writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);

btn.RenderControl(writer);
hid.RenderControl(writer);

writer.RenderEndTag(); //</TD>
writer.RenderEndTag(); //</TR>

writer.RenderEndTag();

}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public enum DataSourceType
{
/// <summary>
/// 往来单位
/// </summary>
Customer,

/// <summary>
/// 部门
/// </summary>
Department
}



上面是控件服务端代码.

在本书中有完整示例讲解.
《庖丁解牛:纵向切入Asp.net 3.5控件和组件开发技术》
--基于VS 2008(兼容VS 2005)C#。本书为Asp.net进阶教材,本书介绍及阅读链接如下:
http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx

近期会把五章控件开发内容发布到此链接. 可以供大家学习.
ChengKing 2008-12-11
  • 打赏
  • 举报
回复
可以做个通用的自定义参照数据选择控件:


namespace KingControls
{
/// <summary>
/// Author: 【夜战鹰】【专注于DotNet技术】【ChengKing(ZhengJian)】
/// 获得本书的更多章节:【http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx】
/// 声明: 【本链接为进阶Asp.net技术的一些文章】【转载时请保留本链接源】
/// </summary>
[DefaultProperty("Text")]
[ValidationProperty("Text")]
[ToolboxData("<{0}:RefrenceControl runat=server></{0}:RefrenceControl>")]
public class RefrenceControl : CompositeControl
{
private Image btn = new Image();
private TextBox txt = new TextBox();
private HiddenField hid = new HiddenField();

[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的值")]
public string Value
{
get
{
this.EnsureChildControls();
if (hid.Value == null)
{
return null;
}
return hid.Value;
}
set
{
this.EnsureChildControls();
hid.Value = value;
}
}

[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的显示文本")]
[ReadOnly(true)]
public string Text
{
get
{
this.EnsureChildControls();
return txt.Text;
}
set
{
this.EnsureChildControls();
txt.Text = value;
}
}

private DataSourceType dstDataSource = DataSourceType.Customer;
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的数据源")]
[TypeConverter(typeof(EnumConverter))]
public DataSourceType DataSource
{
get
{
return dstDataSource;
}
set
{
dstDataSource = value;
}
}

[Category("参照客户端事件")]
[Description("获取或设置返回值处理客户端函数名")]
public string ClientAcceptValueMethod
{
get
{
string s = (string)ViewState["ClientAcceptValueMethod"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["ClientAcceptValueMethod"] = value;
}
}

[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置数据选择页面地址")]
public string RefPage
{
get
{
string s = (string)ViewState["RefPage"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["RefPage"] = value;
}
}

[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置过滤条件")]
public string RefWhere
{
get
{
string s = (string)ViewState["RefWhere"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["RefWhere"] = value;
}
}

private bool blnEnableTextBox = true;
[DefaultValue("true")]
[Category("行为控制")]
[Description("获取或设置文本框可用性")]
public bool EnableTextBox
{
get
{
return blnEnableTextBox;
}
set
{
blnEnableTextBox = value;
}

}

private bool blnEnableButton = true;
[DefaultValue("true")]
[Category("行为控制")]
[Description("获取或设置参照控件按钮的可用性")]
public bool EnableButton
{
get
{
return blnEnableButton;
}
set
{
blnEnableButton = value;
}
}



/// <summary>
/// 设置或获取资源文件夹目录
/// </summary>
[Bindable(true)]
[Category("客户端路径")]
[DefaultValue("")]
[Localizable(true)]
[Description("资源(image/css/js)的客户端根目录")]
public string ClientPath
{
get
{
string s = (string)ViewState["ClientPath"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["ClientPath"] = value;
}
}

public RefrenceControl()
{
this.Width = Unit.Pixel(100);
this.ViewState["RefPage"] = @".\RefPage.aspx";
this.ViewState["ClientPath"] = @".\";
}
protected override void CreateChildControls()
{
hid.ID = "id";
btn.ID = "btn";
txt.ID = "txt";

this.Controls.Add(hid);
this.Controls.Add(txt);
this.Controls.Add(btn);
}

oec2003 2008-12-11
  • 打赏
  • 举报
回复
js + div做的

背景 一个div 满屏 设置透明度

前面显示一个div 设置z-index 大于背景的
hmily821023 2008-12-11
  • 打赏
  • 举报
回复

page1

function Edit()
{
GetItems();
if(arr.length == 1)
{//returnValue 为弹出页面返回值
var returnValue = window.showModalDialog("AddOtherPeopleInfo.aspx?iCustomerID=" + arr[0] + "|" +Form1.txtCustomerID.value, "window", "dialogWidth:950px;dialogHeight:600px;fullscreen:yes;status:no;resizable:no;help:no");
if(returnValue == "1")
{
document.location.reload();
}
}
else
{
if(arr.length == 0)
{
alert("请选择人员后再更新!");
}
else
{
alert("选择条目过多,请重新选择修改项!");
}
}
}

page2
//更新
function Update()
{
var value = checkContent();
if(value)
{
getTerm();
arr.push(Form1.txtCustomerID.value);
var strError = huiyuan.AddOtherPeopleInfo.Update(arr).value;
if(strError == "")
{
alert("更新成功");
window.returnValue = "1";//此处返回值给主窗体
window.close();
}
else
{
alert(strError);
}
}
}

英才网的应该是弹层 不是 window.showModalDialog
这个拿弹层做就不涉及 传值问题了 因为都在一个页面 弹层例子不少 网上找找

62,269

社区成员

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

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

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

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