C# - 从母版页重新加载选项卡

发布于 2024-11-14 11:18:49 字数 148 浏览 2 评论 0原文

我的母版页中有一个 FromDate 和 ToDate 文本框以及一个提交按钮。我有 4 个选项卡,其中包含 4 个不同 URL 的链接,显示各种报告。

现在更改日期并单击提交按钮,我可以根据日期更改更新/重新加载报告(选项卡)吗?

预先非常感谢:)

I have a FromDate and ToDate textboxes and a submit button in my Master page. I have 4 tabs with links for 4 different URLs displaying various reports.

Now on change of Dates and click of submit button, can I update/reload the reports (tabs) based on date change?

Thanks a lot in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你如我软肋 2024-11-21 11:18:49

我建议将您的起始日期和提交按钮移至用户控件。然后,您可以将其放在每个报告上,公开并连接控件上已更改的事件,并公开当前日期文本框的属性以弹出到报告中。

在 Visual Studio 中创建一个用户控件。如果您不确定如何执行此操作,请尝试链接。

使用文本框填充用户控件。像这样的东西:

<div>

<asp:Label ID="FromDateLabel" Text="From:" AssociatedControlID="FromDateTextBox" runat="server" />
<asp:TextBox ID="FromDateTextBox" runat="server" />

<asp:Label ID="ToDateLabel" Text="To:" AssociatedControlID="ToDateTextBox" runat="server" />
<asp:TextBox ID="ToDateTextBox" runat="server" />

<asp:Button ID="UpdateButton" Text="Update" runat="server" 
        onclick="UpdateButton_Click" />

</div>

以及该控件背后的代码。您需要公开一个事件和两个属性,它们可能如下所示:

public partial class ReportDateControl : System.Web.UI.UserControl
{
    public event EventHandler UpdateReport;
    public string FromDate
    {
        get { return this.FromDateTextBox.Text; }
        set { this.FromDateTextBox.Text = value; }
    }
    public string ToDate
    {
        get { return this.ToDateTextBox.Text; }
        set { this.ToDateTextBox.Text = value; }
    }

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        if (UpdateReport != null)
        {
            UpdateReport(this, EventArgs.Empty);
        }
    }
}

在您的 .aspx 页面中,您需要注册控件,这可能如下所示:

<%@ Register Src="~/Controls/ReportDateControl.ascx" TagPrefix="myapp" TagName="ReportDateControl" %>

然后实际将其放在页面上

<myapp:ReportDateControl id="ReportDateControl" 
                         runat="server" 
                         OnUpdateReport="ReportDateControl_UpdateReport" />

:然后连接后面的代码来处理更新事件:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ReportDateControl_UpdateReport(object sender, EventArgs e)
    {
        Controls.ReportDateControl control = (Controls.ReportDateControl)sender;

        string fromDate = control.FromDate;
        string toDate = control.ToDate;

    }
}

在适当的地方更改名称和格式,但这应该会给您一个好主意。

I would suggest moving your from-to dates and submit button to a user control. You can then put that on each report, expose and wire up changed events on your control and expose properties for your from-to date textboxes to pop into your report.

In Visual Studio create a user control. If you are unsure how to do this try this link.

Populate the user control with your text boxes. Something like this:

<div>

<asp:Label ID="FromDateLabel" Text="From:" AssociatedControlID="FromDateTextBox" runat="server" />
<asp:TextBox ID="FromDateTextBox" runat="server" />

<asp:Label ID="ToDateLabel" Text="To:" AssociatedControlID="ToDateTextBox" runat="server" />
<asp:TextBox ID="ToDateTextBox" runat="server" />

<asp:Button ID="UpdateButton" Text="Update" runat="server" 
        onclick="UpdateButton_Click" />

</div>

And the code behind for that control. You'll need to expose an event and the two properties, which might look like this:

public partial class ReportDateControl : System.Web.UI.UserControl
{
    public event EventHandler UpdateReport;
    public string FromDate
    {
        get { return this.FromDateTextBox.Text; }
        set { this.FromDateTextBox.Text = value; }
    }
    public string ToDate
    {
        get { return this.ToDateTextBox.Text; }
        set { this.ToDateTextBox.Text = value; }
    }

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        if (UpdateReport != null)
        {
            UpdateReport(this, EventArgs.Empty);
        }
    }
}

In your .aspx page you'll need to register the control, which might go something like this:

<%@ Register Src="~/Controls/ReportDateControl.ascx" TagPrefix="myapp" TagName="ReportDateControl" %>

And then actually put it on the page:

<myapp:ReportDateControl id="ReportDateControl" 
                         runat="server" 
                         OnUpdateReport="ReportDateControl_UpdateReport" />

And then wire up the code behind to handle the update events:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ReportDateControl_UpdateReport(object sender, EventArgs e)
    {
        Controls.ReportDateControl control = (Controls.ReportDateControl)sender;

        string fromDate = control.FromDate;
        string toDate = control.ToDate;

    }
}

Change the names and formatting where appropriate, but this should give you a good idea.

送你一个梦 2024-11-21 11:18:49

此外,您还可以从母版页公开 Date 控件并通过 Page.Master 属性访问它们。您需要转换为母版页的特定类型才能获取其属性。

Also, you can expose the Date controls from the master page and access them through the Page.Master property. You'll need to cast to the specific type of your master page to get at it's properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文