+ -
当前位置:首页 → 问答吧 → 紧急求助:使用母版页的页面参数传递的方法

紧急求助:使用母版页的页面参数传递的方法

时间:2011-12-09

来源:互联网

测试环境:ASP.NET 程序语言:VB.NET

a.aspx:使用母版页的页面
b.aspx:普通Web页面

a页面中的textbox1文本框输入0后,弹出b页面
b页面上有一个label1标签控件和一个button控件,点击按钮控件关闭b页面,并将标签控件文本传递回a页面,然后更新a页面的textbox1控件值为b页面的label1控件值

经测试目前存在的问题有:
1、IE6中测试:如两个页面为普通WEB页面,测试正常,回传参数值准确;如主页面为使用母版页的WEB页面则测试无反应,参数不能传递回主页面
2、IE9下测试,页面代码报错:Microsoft JScript 运行时错误: 无法设置属性“value”的值: 对象为 null 或未定义

请各位帮助解决,谢谢!

母版页代码:Site1.Master
HTML code
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="WebApplication2.Site1" %>

<!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>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>母版页
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>


a.aspx页面代码:
HTML code
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="a.aspx.vb" Inherits="WebApplication2.a" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
</asp:Content>


b.aspx页面代码:
HTML code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="b.aspx.vb" Inherits="WebApplication2.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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server" Text="9999"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="传递参数" />
    
    </div>
    </form>
</body>
</html>



a.aspx后台程序代码:
VB.NET code
Public Class a
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text = "0" Then Response.Write(" <script> window.open( 'b.aspx','参数窗口', 'height=200, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); </script> ")
    End Sub
End Class


b.aspx后台程序代码:
VB.NET code
Public Class b
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim scriptstr As String
        scriptstr = " <script> window.opener.document.getElementById('textbox1').value= '" & Label1.Text & " '; " & " </script> "
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "return ", scriptstr)
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "close ", " <script> top.opener=null;top.close(); </script> ")

    End Sub
End Class

作者: lovechate   发布时间: 2011-12-09

...路过,我是来打酱油,打酱油的。

作者: sotom   发布时间: 2011-12-09

这哥们帖是不是发错地方了

作者: MrsFeng   发布时间: 2011-12-09