Asp.net发送信息表单页面到页面

时间:2014-06-02 11:28:50

标签: c# javascript asp.net

我正在尝试使用弹出屏幕中的新信息更新旧页面。

我到目前为止所尝试的是将结果保存在会话中

Session["Data"] = DLvrijecampingplaatsen.SelectedItem;

然后在点击Page_Load

时将其加载回旧页面
if (Session["Data"] != null)
{
    LBkiescamping.Text = Convert.ToString(Session["Data"]);
}

它唯一有效的是我首先需要从我页面上的另一个按钮自动回复te页面。所以我的问题是有人知道从我的弹出屏幕回发我的主页的方法吗?

这样我就可以在Reservation.aspx上创建新窗口

<script type="text/javascript">
    function newPopup(url)
        {
            popupWindow = window.open(url, 'popUpWindow', 'height=700,width=1500,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
        }
</script>

然后我通过这个按钮调用这个javascript函数:

<asp:Button runat="server"  Text="Show Map" ID="Btshowmap" onclientclick="javascript:newPopup('Plattegrond.aspx');"/>

在新的Plattegrond.aspx页面中,人们可以通过DropDownList选择露营点。

<asp:DropDownList AutoPostBack="True" ID="Dlbezettecampingplaats" runat="server" OnSelectedIndexChanged="Dlbezettecampingplaats_SelectedIndexChanged"/>

当我选择了一个点我希望将下拉列表的这个selectedindex传递到我的旧页面Reservering.aspx时,按下一个按钮,将关闭发送信息到Storageer.aspx并关闭我的弹出窗口。很遗憾,我可以在Reservering.aspx上接收盒子的信息。但我需要在Reservering.aspx上进行回发以在我的页面上显示新信息。

所以,如果我按下弹出屏幕上的按钮。如何编程此按钮以回发已打开的Reservering.aspx页面?

4 个答案:

答案 0 :(得分:1)

你可以在不使用会话的情况下实现它,请在弹出窗口的jquery中使用window.opener。通过jquery尝试下面的代码。

在Reservation.aspx中添加以下代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Reservation.aspx.cs" Inherits="Web.Reservation" %>

<!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 type="text/javascript">
        function newPopup(url) {
            popupWindow = window.open(url, 'popUpWindow', 'height=700,width=1500,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td colspan="2"><asp:Button runat="server"  Text="Show Map" ID="Btshowmap" onclientclick="javascript:newPopup('Plattegrond.aspx');"/></td>
    </tr>
    <tr>
    <td>Textbox value will be changes</td>
    <td> <asp:TextBox ID="LBkiescamping" runat="server"></asp:TextBox></td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>

在Plattegrond.aspx中添加以下代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Plattegrond.aspx.cs" Inherits="Web.Plattegrond" %>

<!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 src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
      <script type="text/javascript">
          $(document).ready(function () {
              $("#Dlbezettecampingplaats").change(function () {
                  //Get the drop down selected item value in variable 
                  var val = $("#DLvrijecampingplaatsen").val();
                  //Set the value of LBkiescamping textbox value  
                  window.opener.document.getElementById("LBkiescamping").value = val;//.$("#LBkiescamping").val(val);
                 //window.close();
              });
          });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td> In Change of  Dlbezettecampingplaats Dropdown LBkiescamping textbox value will change</td>
    <td>
            <asp:DropDownList runat="server" ID="Dlbezettecampingplaats">
          <asp:ListItem Value="Volvo1" Text="Volvo1"> </asp:ListItem>
             <asp:ListItem Value="Saab1" Text="Saab1"> </asp:ListItem>
                <asp:ListItem Value="Mercedes1" Text="Mercedes1"> </asp:ListItem>
   <asp:ListItem Value="Audi1" Text="Audi1"> </asp:ListItem>
</asp:DropDownList>
    </td>
    </tr>

    <tr>
    <td>Dropdown DLvrijecampingplaatsen selected value will be display in LBkiescamping textbox</td>
    <td>
        <asp:DropDownList runat="server" ID="DLvrijecampingplaatsen">
          <asp:ListItem Value="Volvo" Text="Volvo"> </asp:ListItem>
             <asp:ListItem Value="Saab" Text="Saab"> </asp:ListItem>
                <asp:ListItem Value="Mercedes" Text="Mercedes"> </asp:ListItem>
   <asp:ListItem Value="Audi" Text="Audi"> </asp:ListItem>
</asp:DropDownList>
    </td>
    </tr>

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

答案 1 :(得分:0)

我已经通过这个java函数修复了这个问题

 window.onunload = refreshParent;
 function refreshParent() 
    {
     window.opener.location.reload();
    }

唯一的问题是,当我回到我的旧页面时,firefox会给出下一条消息

Om deze pagina te bekijken moet Firefox gegevens verzenden,waardoor elke handeling die eerder werd uitgevoerd(zoals zoeken of online aankopen)zal worden herhaald。

Firefox message

如何禁用此功能?

答案 2 :(得分:0)

而不是使用服务器端代码,会话。你可以使用javascript代码完成此操作。 在你的页面中,添加javascript函数来更新lable,这将从弹出页面调用。 在page1.aspx

  function updateLBkiescamping(val){
     document.getElementById('<%= LBkiescamping.ClientID %>').innerText = val;
  }
popup.aspx中的

 function updateParent(){
   var ddl = document.getElementById('<%=DLvrijecampingplaatsen %>'); 
  window.opener.updateLBkiescamping( ddl.options[ddl.selectedIndex].text);
  //if you need close popup
  //window.close();
 }

updateParent甚至需要在弹出页面中调用一些按钮

   <input type="button" value="update" onclick="updateParent();" />

答案 3 :(得分:0)

我发现它是最好的一个使用timmer来检查弹出窗口是否已关闭然后更新按钮。

你仍然必须使用会话来保存页面之间的新值。

var interval;
    var popupWindow;
    function newPopup(url) {
        popupWindow = window.open(url, 'popUpWindow', 'height=1000,width=1500,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');
        interval = window.setInterval(function () {
            if (popupWindow == null || popupWindow.closed)
            {
                document.getElementById("refreshMe").click()
            }
        }, 1000);
    }

它工作得很好只剩下这个刷新触发我的页面上的验证器,所以如果有些感觉是空的,那么wil会出现。

但感谢al的反应:)