views:

215

answers:

2

Hi,

I have the following structure in place and need to rebind the lower control (DropDownList) from the code behind of the MainPage.

x MainPage1 x---- Panel1 (modal popup)
x--------- UpdatePanel (upMailOrStatusAction, on Panel1)
x-------------- RadioButtonList (rblActionLevel, on UpdatePanel)
x-------------- SubForm1 (on Panel1)
x------------------- CustomControl1 (on Subform1)
x------------------------ DropDownList (on CustomControl1)

What would be the correct way to accomplish this?

I added a public method "BindMailActionLookup()" to the control, but how do I call it from the main page? I get "does not exist in the current context"?

Here is the markup of the subform:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MailAddSubform.ascx.cs" 
Inherits="Company.Solutions.Web.Controls.MailAddSubform" %>

<%@ Register TagPrefix="st" TagName="MailActionLookup" Src="~/Controls/StMailActionLookup.ascx" %>
<div class="NinetyNinePercentWide">
    <div class="NinetyNinePercentWide EightPixelBottomMargin">
        <div class="RowHeader" style="padding-top: 20px;">
            <span class="labelfield" >Action:</span>
        </div>
        <div>
            <st:MailActionLookup ID="mailActionLookup" runat="server" />
        </div>
    </div>
    <div class="NinetyNinePercentWide EightPixelBottomMargin" >
        <br class="NinetyNinePercentWide" Text="&nbsp" />
        <div class="RowHeader" >
            <span class="labelfield" >Message:</span>    
        </div>
        <div class="TwelvePixelLeftPad" >
            <asp:TextBox ID="txtMailActionMessage" runat="server" MaxLength="40" />
        </div>
    </div>
</div>

Here is the markup for the custom control:

<%@ Control Language="C#" AutoEventWireup="true"        CodeBehind="StMailActionLookup.ascx.cs"     Inherits="Company.Solutions.Web.Controls.StMailActionLookup" %>


<div id="mainControlContainer" style="width:99%; padding:8px;">

<div id="comboContainer" style="float:left; padding-top:12px;padding-left:5px; padding- right:5px; padding-bottom:3px;">
  <asp:UpdatePanel runat="server" ID="mailActionUpdater">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="chkForms" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="chkRequested" EventName="CheckedChanged" />
        <asp:AsyncPostBackTrigger ControlID="chkOther" EventName="CheckedChanged" />
    </Triggers>
    <ContentTemplate>
        <asp:DropDownList runat="server" ID="ddlLookup" width="240px" ondatabound="ddlLookup_DataBound1" /> 
    </ContentTemplate>
  </asp:UpdatePanel>


</div>

<div id="filterContainer" style="text-align:left;padding-left:6px;width:275px">
    <fieldset style="width:260px;">
        <legend>Filters</legend>
        <asp:CheckBox ID="chkForms" runat="server" Text="Forms" AutoPostBack="true" />
        <asp:CheckBox ID="chkRequested" runat="server" Text="Requested Info" AutoPostBack="true" />
        <asp:CheckBox ID="chkOther" runat="server" Text="Other" AutoPostBack="true" />
    </fieldset>

</div>    
</div>

And here is part of the code behind where I added the public method:

namespace Company.Solutions.Web.Controls
{
    public partial class StMailActionLookup : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           BindForm();
        }

        public void BindMailActionLookup()
        {
            BindForm();
        }

        protected void BindForm()
        {
            GetActionLevel();
            IEnumerable actions = GetClaimMailActions(GetFilter());
            ddlLookup.DataSource = actions;
            ddlLookup.DataTextField = "CodeAndDescription";
            ddlLookup.DataValueField = "ActionCd";
            ddlLookup.DataBind();
        }
    }
}

Thank you, James

+1  A: 

You shouldn't be exposing the internals of CustomControl1 to a consumer, so the most correct way would be to expose a public method (maybe call it "ResetDropDowns") on your CustomControl1 that the main page could call into.

CustomControl1 knows about it's own dropdowns, so it can easily find and rebind the control when someone calls the method.

womp
That makes sense, I will try that out. Thanks
James
Ok,I added a public method "BindMailActionLookup()" to the control, but how do I call it from the main page? I get "does not exist in the current context"?
James
See code above, how do I call BindMailActionLookup() from the main page? Or am I totally wrong with this?Thanks
James
Hey James... can you post some more code? When are you calling it? What does "BindForm()" look like? Is that a compiler error or is it a runtime error?
womp
I have added additional code. Not compiler or runtime error. I get that when trying to write the call: BindMailActionLookup();
James
How to complete this is the question?mailAddSubform.???.BindMailActionLookup();
James
You should be able to do "mailActionLookup.BindMailActionLookup()".
womp
If I start with mailActionLLookup I still get "does not exist in the current context". If I try this: mailAddSubform.mailActionLookup.BindMailActionLookup(), then I get "mailActionLookup is inaccessable due to it's protection level".
James
You need to make the mailActionLookup control a public member of the subform.
womp
Thanks womp, you prompted me along to finally get a resolution.
James
A: 

Ok, we have a solution thanks to "womp's" suggestions and one of my co-workers. Just keep nesting the public calls in a chain:

This in the main Claim Info code behind:

    // Rebind the action code drop down to restrict to base level 
    mailAddSubform.BindMailActionLookup();

Then this in the subform code behind:

    public void BindMailActionLookup()
    {
        mailActionLookup.BindMailActionLookup();
    }

And finally, this in the lookup control:

  public void BindMailActionLookup()
    {
        BindForm();
    }
James