在子窗体点击按钮后,,,传递一个参数到父窗体,,并刷新父窗体输出该参数.???

cookies10wen 2009-03-17 01:54:47
如题..WEBFORM..服务器控件...
...全文
232 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
cookies10wen 2009-03-18
  • 打赏
  • 举报
回复
Sandy945 你真利害...呵呵....
阿非 2009-03-17
  • 打赏
  • 举报
回复

Dim js As String = "<script> var str=window.opener.location.href; "
js += "if (str.indexOf('?')==-1) window.opener.location=window.opener.location+'?value='+document.getElementById('txt').value; "
js += " else window.opener.location=window.opener.location+'&value='+document.getElementById('txt').value; </script>"
ClientScript.RegisterStartupScript([GetType](), "refreshOpener", js)
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复

string js = @"<script>
var str=window.opener.location.href;
if(str.indexOf('?')==-1)
{
window.opener.location=window.opener.location+'?value='+document.getElementById('txt').value;
}
else
window.opener.location=window.opener.location+'&value='+document.getElementById('txt').value;

</script>";
ClientScript.RegisterStartupScript(GetType(), "refreshOpener", js);



这段代码能用VB.net写的么..我想用vb.net写..嘻嘻....十分感谢Sandy945!!
阿非 2009-03-17
  • 打赏
  • 举报
回复
在子页面中的button 中 把 OnClientClick="refreshOpener();" 去掉

在button 的单击事件中加上 ...后面的


protected void Button1_Click(object sender, EventArgs e)
{
Conn.Open();
SqlCommand SqlCommandInsert = new SqlCommand();
SqlCommandInsert.Connection = Conn;
SqlCommandInsert.CommandText = "ClothInsert";
SqlCommandInsert.CommandType = CommandType.StoredProcedure;
SqlCommandInsert.Parameters.Add("@ClothInNo", SqlDbType.VarChar).Value = this.ClothInNo.Text;
SqlCommandInsert.Parameters.Add("@InputDateTime", SqlDbType.SmallDateTime).Value = this.InputDateTime.Text;
SqlCommandInsert.Parameters.Add("@ClothNo", SqlDbType.VarChar).Value = this.ClothNo.Text;
SqlCommandInsert.Parameters.Add("@ClothIngredient", SqlDbType.VarChar).Value = this.ClothIngredient.Text;
SqlCommandInsert.Parameters.Add("@Width", SqlDbType.VarChar).Value = this.Width.Text;
SqlCommandInsert.Parameters.Add("@InAmount", SqlDbType.Int).Value = this.InAmount.Text;
SqlCommandInsert.Parameters.Add("@Price", SqlDbType.Money).Value = 1.25;
SqlCommandInsert.Parameters.Add("@AllMoney", SqlDbType.Money).Value = this.AllMoney.Text;
SqlCommandInsert.Parameters.Add("@Remark", SqlDbType.VarChar).Value = this.Remark.Text;
SqlCommandInsert.Parameters.Add("@Pictrue", SqlDbType.VarChar).Value = "";
SqlCommandInsert.Parameters.Add("@IpAddress", SqlDbType.VarChar).Value = Request.ServerVariables("REMOTE_ADDR");
SqlCommandInsert.ExecuteNonQuery();

...
string js = @"<script>
var str=window.opener.location.href;
if(str.indexOf('?')==-1)
{
window.opener.location=window.opener.location+'?value='+document.getElementById('txt').value;
}
else
window.opener.location=window.opener.location+'&value='+document.getElementById('txt').value;

</script>";
ClientScript.RegisterStartupScript(GetType(), "refreshOpener", js);
}

liaoyunt07 2009-03-17
  • 打赏
  • 举报
回复
不用刷新,也能得到子窗体的参数~
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
其实我的想法是,,在子页面增加记录,,增加后把编号传给父页面,,并马上刷新显示,,,如果先执行OnclientClick,,那么就是先刷新显示,,后增加记录,,这样子实现不了,,,请问有更好的办法实现吗???谢谢..
阿非 2009-03-17
  • 打赏
  • 举报
回复
先执行 OnClientClick

先执行客户端,然后是服务器
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
再问一下,,,这样子是先执行OnClientClick="refreshOpener(); 还是先执行后台的click...??
阿非 2009-03-17
  • 打赏
  • 举报
回复
OnClientClick="refreshOpener();return false"

你把return false 去了
写成

OnClientClick="refreshOpener();"
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
是不是两个Click只能执行一个??
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复

protected void Button1_Click(object sender, EventArgs e)
{
Conn.Open();
SqlCommand SqlCommandInsert = new SqlCommand();
SqlCommandInsert.Connection = Conn;
SqlCommandInsert.CommandText = "ClothInsert";
SqlCommandInsert.CommandType = CommandType.StoredProcedure;
SqlCommandInsert.Parameters.Add("@ClothInNo", SqlDbType.VarChar).Value = this.ClothInNo.Text;
SqlCommandInsert.Parameters.Add("@InputDateTime", SqlDbType.SmallDateTime).Value = this.InputDateTime.Text;
SqlCommandInsert.Parameters.Add("@ClothNo", SqlDbType.VarChar).Value = this.ClothNo.Text;
SqlCommandInsert.Parameters.Add("@ClothIngredient", SqlDbType.VarChar).Value = this.ClothIngredient.Text;
SqlCommandInsert.Parameters.Add("@Width", SqlDbType.VarChar).Value = this.Width.Text;
SqlCommandInsert.Parameters.Add("@InAmount", SqlDbType.Int).Value = this.InAmount.Text;
SqlCommandInsert.Parameters.Add("@Price", SqlDbType.Money).Value = 1.25;
SqlCommandInsert.Parameters.Add("@AllMoney", SqlDbType.Money).Value = this.AllMoney.Text;
SqlCommandInsert.Parameters.Add("@Remark", SqlDbType.VarChar).Value = this.Remark.Text;
SqlCommandInsert.Parameters.Add("@Pictrue", SqlDbType.VarChar).Value = "";
SqlCommandInsert.Parameters.Add("@IpAddress", SqlDbType.VarChar).Value = Request.ServerVariables("REMOTE_ADDR");
SqlCommandInsert.ExecuteNonQuery();
}
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
我也晕了...问题又来了...我的按钮在后台写的代码执行不了....
阿非 2009-03-17
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 cookies10wen 的回复:]
这种方法我试过,,但是我的是服务器控件,,加上 onclick="refreshOpener();" 就会出错:

编译器错误信息: BC30456: “refreshOpener”不是“ASP.clothinsert_aspx”的成员。
[/Quote]

我真晕,在那个帖子里 我就回复过了啊~ 在那个帖子的9楼
CutBug 2009-03-17
  • 打赏
  • 举报
回复
onclick是server方法,客户端click是clientclick

<asp:Button ID="Button1" runat="server" Text="确定" ForeColor="Black" OnClientClick="refreshOpener();return false" />
zzxap 2009-03-17
  • 打赏
  • 举报
回复
opener.document.getElementById('txt').value
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复

<asp:Button ID="Button1" runat="server" Text="确定" ForeColor="Black" onclick="refreshOpener();" />
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
这种方法我试过,,但是我的是服务器控件,,加上 onclick="refreshOpener();" 就会出错:

编译器错误信息: BC30456: “refreshOpener”不是“ASP.clothinsert_aspx”的成员。
阿非 2009-03-17
  • 打赏
  • 举报
回复

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="B.aspx.cs" Inherits="B" %>

<!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>
<script>
function refreshOpener()
{
var str=window.opener.location.href;
if(str.indexOf("?")==-1)
{
window.opener.location=window.opener.location+'?value='+document.getElementById('txt').value;
}
else
window.opener.location=window.opener.location+'&value='+document.getElementById('txt').value;
}
</script>
</head>

<body>
<form id="form1" runat="server">
<div>
<input type="text" id="txt" />
<input type="button" value="刷新父页并输出参数" onclick="refreshOpener();" />

</div>
</form>
</body>
</html>

xiaohe185 2009-03-17
  • 打赏
  • 举报
回复
仅供参考,其实,很多东西都是举一反三的,从中应该有所启发吧,我认为
cookies10wen 2009-03-17
  • 打赏
  • 举报
回复
上次是关闭时候传递刷新,,,这次是点击按钮,,,呵呵...
加载更多回复(5)
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 在C# WinForm开发中,子窗体有时需要操作或更新窗体的状态,例如刷新窗体内容或修改窗体控件的值。以下是两种实现方式的详细说明。 方法一:使用委托 通过定义一个自定义委托SetVisiableHandler,将窗体的方法传递到子窗体中,子窗体可以在需要时调用该方法来改变窗体的控件状态。具体步骤如下: 在窗体Form2中定义委托类型SetVisiableHandler以及相关处理方法。 当打开子窗体Form3时,将SetVisiable方法作为参数传递给子窗体。 子窗体Form3接收并存储该委托,在按钮点击事件btnVisible_Click中调用它。 以下是代码示例: 方法二:使用公共变量 通过在窗体和子窗体之间共享公共变量来实现通信。具体步骤如下: 在窗体Form4中定义一个公共属性StrLabel1,用于存储需要传递的值。 子窗体Form5通过访问这个公共变量来获取或设置窗体的值。 子窗体在操作完成后,通过修改公共变量来更新窗体的状态。 以下是代码示例: 这两种方法都可以实现子窗体窗体的控制,但需要注意窗体之间的关系,例如通过Owner属性或手动传递引用。频繁的跨窗体交互可能会增加复杂性,因此在设计时应考虑清晰的结构和通信方式,避免不必要的耦合。总的来说,在C# WinForm开发中,子窗体窗体的交互可以通过委托、公共变量等多种方式实现。选择哪种方法取决于具体需求和项目结构,实际应用中应注重代码的可读性和维护性。

62,268

社区成员

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

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

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

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