0

我使用 2 个 Web 表单,我想使用一个 Web 表单,然后我想用第二个 Web 表单打开一个对话框。如果我单击 ListView 中的 LinkBut​​ton,我想打开对话框,它工作正常,但我需要第二个 Webform 的值,所以我首先打开对话框。此对话框为空。关闭此对话框后,值将发送到会话。

ASPX:

...
<script type="text/javascript">

         function OpenChild() {

             var WinSettings = "center:yes;resizable:no;dialogHeight:550px"
             var MyArgs = window.showModalDialog("Benutzer.aspx", MyArgs, WinSettings);

         }

    </script>
...
<asp:ListView runat="server" ID="myListView">

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0" width="800" cellpadding="0" cellspacing="0">
                <tr style="background-color:#E5E5FE" class="TableClass">
                    <th id="th1" runat="server"><asp:LinkButton ID="lnkBenutzer" runat="server" >id_Benutzer</asp:LinkButton></th>
                    <th id="th2" runat="server"><asp:LinkButton ID="lnkemail" runat="server" >id_Email</asp:LinkButton></th>
                    <th id="th3" runat="server"><asp:LinkButton ID="lnkVorname" runat="server" >id_Vorname</asp:LinkButton></th>
                    <th id="th4" runat="server"><asp:LinkButton ID="lnkNachname" runat="server" >id_Nachname</asp:LinkButton></th>
                    <th id="th5" runat="server"><asp:LinkButton ID="lnkTelefon" runat="server" >id_Telefon</asp:LinkButton></th>
                </tr>
                <tr runat="server" id="ItemPlaceholder">
                </tr>
            </table>
        </LayoutTemplate>

        <ItemTemplate>

            <tr class="TableClass">    
                <td align="left" ><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" OnClientClick="OpenChild()" /></td>

              <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr class="TableClass"> 

                <td align="left" ><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" OnClientClick="OpenChild()" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" OnCommand="Button1_Command" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" OnClientClick="OpenChild()" /></td>

                <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </AlternatingItemTemplate>

        </asp:ListView>

C#代码:

...

protected void Button1_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                //Der Index der Zeile wird ermitellt
                int index = Convert.ToInt32(e.CommandArgument);

                //Der Inhalt (GUID[Unsichtbar]) wird aus der zeile mit dem Index herausgezogen und übergeben
                Label lb = (Label)myListView.Items[index].FindControl("Label6");

                //Der GUID, Benutzer-Nachname und das Werk werden an eine Session übergeben
                Session["UserID"] = lb.Text;
                Session["SearchUser"] = txtBenutzer.Text;
                Session["DropDownValue"] = dropWerk.SelectedValue;


                //Es wird eine neue Webform geöffnet
                Response.Redirect("Benutzer.aspx",true);

            }

        }

...

我希望我将我的值保存在会话中,然后打开对话框

塔拉索夫

4

2 回答 2

1

如果我正确理解您的问题,是的,您可以使用带有 ClientScriptManager.RegisterStartupScript 方法的 javascript 服务器端,这是一篇 msdn 文章,详细解释了它

http://msdn.microsoft.com/en-us/library/asz8zsxy.aspx

于 2012-08-13T11:15:27.343 回答
0

Javascript 代码总是在服务器端代码之前被调用..你必须考虑替代方式...你可以使用 List View 的 ItemCommand 属性来设置会话值,然后从 Codebehind 调用 Javascript 函数来打开弹出窗口。

protected void ListView_OnItemCommand(object sender, ListViewCommandEventArgs e)
  {
    if (String.Equals(e.CommandName, "OpenPopup"))
    {

      ListViewDataItem dataItem = (ListViewDataItem)e.Item;
      Session["UserID"]=((Label)dataItem.FindControl("Label6")).Text;
      Session["SearchUser"] = txtBenutzer.Text;                     
      Session["DropDownValue"] = dropWerk.SelectedValue;
      Page.ClientScript.RegisterStartupScript(GetType(), "Key", "OpenPopupFunction();", true); 

    }     

}
于 2012-08-13T12:40:17.650 回答