本人希望实现下面的功能,高手提供一下解决方案:
1、主页面通过一个Button按钮的Click事件中触发一个弹出窗口,并且传一个动态生成的变量值过去;
2、子窗口根据传来的值,动态查询数据库绑定Gridview控件,选择一个特定的记录集,并提交子页面;
3、关闭子页面,并把子页面的值带回到主页面,赋值在一个特定的Label控件上面上述功能,希望尽量功能通过后台代码结合javascript来实现(如,使用ClientScriptManager类或一些方法),不要全部javascript,因为本人对javascript不太了解。所以请教各位高手给出这个功能的设计思路和具体方法,最好给出Demo代码加以说明,谢谢!
1、主页面通过一个Button按钮的Click事件中触发一个弹出窗口,并且传一个动态生成的变量值过去;
2、子窗口根据传来的值,动态查询数据库绑定Gridview控件,选择一个特定的记录集,并提交子页面;
3、关闭子页面,并把子页面的值带回到主页面,赋值在一个特定的Label控件上面上述功能,希望尽量功能通过后台代码结合javascript来实现(如,使用ClientScriptManager类或一些方法),不要全部javascript,因为本人对javascript不太了解。所以请教各位高手给出这个功能的设计思路和具体方法,最好给出Demo代码加以说明,谢谢!
子窗口后台读值后处理逻辑
子页面传值用windown.opener的方式设父页面的Label控件
var v="124";//需要传递到子页面的js变量,自己设定
</script>
<input type="button" value="打开子页面" onclick="window.open('child.aspx?v='+v)"/>child.aspx获取参数v然后查询数据库
然后使用opener得到父页引用,然后选择内容后使用opener操作父页的label,给label赋值,最后self.close()
有楼主想要的
仔细找一下
<script type="text/javascript">
function ShowDialog(sURL, obj, iWidth, iHeight)
{
var oDialog = showModalDialog(sURL, obj, "dialogWidth:" + iWidth.toString() + "px;dialogHeight:" + iHeight.toString() + "px;help:no;scroll:yes;status:yes");
return oDialog;
}
</script><asp:TextBox ID="txtValue" runat="server" CssClass="FormBase" style="width:220px;"></asp:TextBox><input id="btn" type="button" class="ManagerButton" onclick="ShowDialog('子窗口的URL.aspx', window.document, 550, 300);" />子窗口
<script type="text/javascript">
function ClickDialog(value)
{
window.dialogArguments.getElementById("txtValue").value = value;//将值返回到父窗口的TextBox控件上
window.close();
}
</script><a href="#" onclick="ClickDialog('<%= %>')">选定</a>
希望对你有用
还是希望大家能够尽量用后台代码中.NET提供的API类来解决,当然可以适当配合脚本
第一种方案是:
file a.htmfunction OpenDialog(url,param)
{
return window.open(url,param, "DialogWidth:450px;DialogHeight:450px;help:no;status:no");
}
file b.htm
<script language="javascript">
function js_do(val)
{
self.opener.document.all.filename.value=val
}
</script>第二种方案是:
file A.htm
<html>
<script language="javascript">
function OpenDialog(url,param)
{
return window.showModalDialog(url,param, "DialogWidth:450px;DialogHeight:450px;help:no;status:no");
}function js_getData(url)
{
return OpenDialog("b.htm","");
}</script>
<body>
<form name="myFrm">
<input type="text" name="filename" onclick="this.value=js_getData()">
</form>
</body>
</html>file b.htm<html>
<script language="javascript">
function js_do(val)
{
window.returnValue=val;
window.close();
}
</script>
<body>
<form name="myFrm">
<input type="text" name="filename">
<input type="text" name="btnDo" onclick="js_do(this.form.filename.value)">
</form>
</body>
</html> Response.Write("<script language='javascript'>window.opener.document.all.txt1.value="+theValue+";</script>");
javascript出错,你自己调试一下atpains,你的方法我试过了,思路我明白了,但是在执行ClickDialog(value)方法时,总是提示脚本错误,我估计是“window.dialogArguments.getElementById("txtValue").value”这句话有问题,所以无法回传值!
还是希望大家能够尽量用后台代码中.NET提供的API类来解决,当然可以适当配合脚本~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~估计是"txtValue"的问题,还是把你控件的ClientID传到这里使用后台代码,无非你RegisterStartupScript(....)
说你要求高,是指希望别人把完整的,好的,代码都写好了给你.
你还是自己动手尝试,
像javascript出错,你可以自己找找原因.
否则,永远是不会.