开发者

C# - Reload tabs from Master page

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 :)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜