在c#中从父参数传递到iframe

本文关键字:参数传递 iframe | 更新日期: 2023-09-27 18:06:50

我有一个树视图菜单在我的默认。aspx页面和一组在参数中带有几个控件的面板。aspx页面。参数。在iframe中导入aspx为Default。根据用户选择的treeNode,参数中的一些面板。Aspx要么是可见的,要么是隐藏的。例如,如果用户选择第一个节点,则隐藏面板4,但如果用户选择第二个节点,则显示所有面板。(我把它们分开是因为参数。aspx进行回发,每次选择treeNode时都会打开一个新选项卡)。我试过了& lt;iframe id="iframe" runat="server" src="Parameters.aspx?Param1=<%=treeview_reportName%>" class="noba"滚动="no">

然后用querystring调用它但我得到一个变量不存在的错误。当我尝试传递一个会话时,当我从Parameters.aspx调用它时,它总是返回null后面的代码都是c#

Default.aspx:

    <asp:TreeView ID="treeReport" runat="server" DataSourceID="XmlDataSource1" 
                    ImageSet="Arrows" NodeWrap="True" Width="250px" 
                    LeafNodeStyle-NodeSpacing="2.5px" Font-Names="Arial,Helvetica,sans-serif"
                    OnSelectedNodeChanged="treeReport_SelectedNodeChanged">
                    <DataBindings>
                        <asp:TreeNodeBinding DataMember="ReportTitle" ValueField="Name" 
                            PopulateOnDemand="True" Target="_self"/>
                        <asp:TreeNodeBinding DataMember="ChildReport" ValueField="Value" 
                            PopulateOnDemand="True" Target="_self"/>
                        <asp:TreeNodeBinding DataMember="Reports" ValueField="#Name" Target="_self" />
                    </DataBindings>
                    <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
                    <LeafNodeStyle NodeSpacing="2px" />
                    <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" 
                        HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
                    <RootNodeStyle Font-Bold="True" Font-Size="8pt"/>
                    <ParentNodeStyle Font-Bold="True" />
                    <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" 
                        HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>

树视图背后的代码是

protected void treeReport_SelectedNodeChanged(object sender, EventArgs e)
        {
            string treenodeText = treeReport.SelectedNode.Text;
            string treeview_reportName = "summary";
            switch (treenodeText)
            {
                case "Overall incident analysis":
                    treeview_reportName = "overall";
                    break;
                case "All incidents":
                    treeview_reportName = "summary";
                    break;
                default:
                    treeview_reportName = "overall";
                    break;
            }
            Session["ReportGenerate"] = treeview_reportName;
        }

和参数。aspx

<asp:Panel ID="pn1" runat="server" Width="610px" Visible="true" CssClass="project-content" >
 //Some controls here
</asp:Panel>
<asp:Panel ID="pn2" runat="server" Width="610px" Visible="true" CssClass="project-content" >
 //Some controls here
</asp:Panel>
<asp:Panel ID="pn3" runat="server" Width="610px" Visible="true" CssClass="project-content" >
 //Some controls here
</asp:Panel>
<asp:Panel ID="pn4" runat="server" Width="610px" Visible="true" CssClass="project-content" >
 //Some controls here
</asp:Panel>

在c#中从父参数传递到iframe

我认为使用Session在页面之间传递参数只能作为最后的手段。我认为在这种情况下,querystring是一个更好的选择。

一个选项是在SelectedNodeChange回发事件中设置iframe控件的src属性。您需要确保iframe控件具有runat=server属性。请看下面的代码:

 protected void treeReport_SelectedNodeChanged(object sender, EventArgs e)
 {
        string treenodeText = treeReport.SelectedNode.Text;
        string treeview_reportName = "summary";
        switch (treenodeText)
        {
            case "Overall incident analysis":
                treeview_reportName = "overall";
                break;
            case "All incidents":
                treeview_reportName = "summary";
                break;
            default:
                treeview_reportName = "overall";
                break;
        }
        iframe.Attributes.Add("src", 
             string.Format("Parameters.aspx?Param1={0}", treeview_reportName));
 }

在我的版本中,我需要知道从哪个页面我得到Ifarme,所以我这样使用它在我进入iframe的页面里面有这个

 <iframe runat="server" id="YourID"  name="YOURname" src="MY_Frame.aspx?source_page=Mypage"></iframe>

在我的框架的c#里面,我把(在Page_Load内)

String SourcePage = Request.QueryString["source_page"].ToString();

你得到(SourcePage =MYpage)

希望对你有帮助

                Mensaje = "Se envio una notificación al Agente: ";
                HtmlControl contentPanel1 = (HtmlControl)this.PnlError.FindControl("Iframe1");
                contentPanel1.Attributes["src"] = "../webMPH/wGeneroEnvio.aspx?lblMensaje=" + Mensaje.Trim()
                                                                           + "&lblUsuario=" + NombreAgente
                                                                           + "&lblMail=" + MailAgente;