我有以下aspx页面,其中包含一系列用于获取参数的下拉框,以及一系列调用基于参数加载各个图表的iFrame。页面正文如下:
<body>
<form id="bmBehaviorForm" runat="server">
<div class="row">
<div runat="server">
<asp:DropDownList ID="ddSchoolYear" AutoPostBack="true" OnSelectedIndexChanged="ddValueChanged" runat="server"></asp:DropDownList>
<asp:DropDownCheckBoxes ID="ddSchoolType" UseButtons="true" UseSelectAllNode="true" OnSelectedIndexChanged="ddValueChanged" runat="server">
<Style2 DropDownBoxBoxWidth="200" SelectBoxCssClass="selectHeight" />
<Texts SelectBoxCaption="School Type" />
</asp:DropDownCheckBoxes>
<asp:DropDownCheckBoxes ID="ddSchools" UseButtons="true" UseSelectAllNode="true" OnSelectedIndexChanged="ddValueChanged" runat="server">
<Style2 DropDownBoxBoxWidth="350" SelectBoxCssClass="selectHeight" />
<Texts SelectBoxCaption="Schools" />
</asp:DropDownCheckBoxes>
<asp:DropDownCheckBoxes ID="ddGrades" UseButtons="true" UseSelectAllNode="true" RepeatColumns="2" RepeatDirection="Vertical"
OnSelectedIndexChanged="ddValueChanged" runat="server">
<Style2 DropDownBoxBoxWidth="150" SelectBoxCssClass="selectHeight" />
<Texts SelectBoxCaption="Grades" />
</asp:DropDownCheckBoxes>
<asp:DropDownCheckBoxes ID="ddEvent" UseButtons="true" UseSelectAllNode="true" OnSelectedIndexChanged="ddValueChanged" runat="server">
<Style2 DropDownBoxBoxWidth="400" DropDownBoxBoxHeight="5000" SelectBoxCssClass="selectHeight" />
<Texts SelectBoxCaption="Behavior Events" />
</asp:DropDownCheckBoxes>
<asp:DropDownCheckBoxes ID="ddResolution" UseButtons="true" UseSelectAllNode="true" OnSelectedIndexChanged="ddValueChanged" runat="server">
<Style2 DropDownBoxBoxWidth="400" DropDownBoxBoxHeight="5000" SelectBoxCssClass="selectHeight" />
<Texts SelectBoxCaption="Resolutions" />
</asp:DropDownCheckBoxes>
</div>
</div>
<div class="row rowPaddingTop">
<iframe name="iName_iSchools" id="iSchools" style="border: none;" width="775px" height="500px"
src="behaviorbySchool.aspx"></iframe>
<iframe name="iName_iGrades" id="IGrades" style="border: none;" width="775px" height="350px"
src="behaviorbyGrade.aspx"></iframe>
<iframe name="iName_iMonths" id="IMonths" style="border: none;" width="775px" height="350px"
src="behaviorbyMonth.aspx"></iframe>
<iframe name="iName_iLocations" id="ILocations" style="border: none;" width="775px" height="350px"
src="behaviorbyLocation.aspx"></iframe>
<iframe name="iName_iDemographicsYTD" id="IDemographicsYTD" style="border: none;" width="800px" height="400px"
src="behaviorbyDemographics.aspx?ytd=1"></iframe>
<iframe name="iName_iDemographicsMTH" id="IDemographicsMTH" style="border: none;" width="800px" height="400px"
src="behaviorbyDemographics.aspx?ytd=0"></iframe>
</div>
</form>
在每个iFrame的代码隐藏中,我想引用调用表单中的下拉框来获取所选值。我一直在尝试各种形式的代码,但我的语法不正确。我怎么能这样做?
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace DMC.BM
{
public partial class behaviorBySchool : System.Web.UI.Page
{
refData rd = new refData();
protected void Page_Load(object sender, EventArgs e)
{
form1 frm = (form1)FindControl("bmBehaviorForm");
}
}
}
修改 在获得下面这些令人敬畏的答案和说明之后,我认为我要做的是用javascript替换iFrame来构建我的图形。我正在使用Highcharts,但最近发现了dotnet Highcharts - 我在每个iFrame中构建了dotnet Highcharts。我想我会放弃这一点,只使用javascript中的基础Highcharts构建我的图表,这将解决我的所有问题。
答案 0 :(得分:1)
您尝试做的事情是不可能的。至少以你目前拥有它的方式。 ASP.NET不知道你的iframe是什么。 iframe是一个纯粹的客户端想法。
你真的想要iframe,或者你是否只想拥有可以从后面的代码中访问的可重用的代码/内容?如果是后者(几乎可以肯定你想要的话),你应该把你的.aspx页面放到ASP.Net UserControls中。在您这样做之后,然后您可以按我认为的方式访问这些控件。
答案 1 :(得分:0)
服务器上不存在这些表单的实例。即使他们这样做,他们之间也没有联系。
将iframe
表单所需的任何数据放入您分配给iframe.src
属性的网址的查询字符串部分中。然后,您就可以在iframe
页面中访问这些数据了。 C#代码为Request["ytd"]
。