lundi 21 décembre 2015

Access specific control from another custom control backend class in ASP.NET Web forms

Is it possible to access specific control with-in a custom made ASP.NET control from another one? In other words, I have made custom control in ASP.NET:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BankInformationGridView.ascx.cs" Inherits="Valitor.Acquiring.Abs.Web.Common.Controls.BankInformationGridView" %>

<%@ Register src="~/Controls/BankInformation.ascx" tagname="BankInformation" tagprefix="ABS" %>

<asp:UpdatePanel runat="server" ID="upBankInformationDirectDebit" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="control-group">
            <asp:GridView ID="gvBankInformationDirectDebit" runat="server" GridLines="None" CssClass="table" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="IBAN" meta:resourcekey="IBAN" />
                    <asp:BoundField DataField="SwiftCode" meta:resourcekey="SwiftCode" />
                    <asp:BoundField DataField="AccountNumber" meta:resourcekey="AccountNumber" />
                    <asp:TemplateField ItemStyle-HorizontalAlign="Right" ItemStyle-Wrap="false"></asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
        <div>
            <ABS:BankInformation runat="server" ID="bankInformation"/>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

I have another custom control that is referencing the first one and instantiating it in a hidden div.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DirectDebit.ascx.cs" Inherits="Valitor.Acquiring.Abs.Web.Management.Controls.DirectDebit" %>
<%@ Register src="~/Controls/BankInformationGridView.ascx" tagname="BankInformationGridView" tagprefix="ABS" %>

    <script type="text/javascript">
        function OpenAddressDialog(dialogID) {
            $("#" + dialogID).modal();
        }

        function ValidateAndCloseAddressDialog(validationGroup, dialogID) {
            var pageValid = Page_ClientValidate(validationGroup);
            if (pageValid)
                $("#" + dialogID).modal("hide");
        });
    </script>
    <asp:CheckBox runat="server" ID="chkDirectDebit" />
    <asp:Label runat="server" AssociatedControlID="chkSameAsMerchantBank" ID="txtDirectDebit" meta:resourcekey="lblDirectDebit"></asp:Label>
    <asp:CheckBox runat="server" ID="chkSameAsMerchantBank" OnCheckedChanged="chkSameAsMerchantBank_CheckedChanged" AutoPostBack="True" Checked="True"/>
    <asp:Label runat="server" AssociatedControlID="txtSameAsMerchantBank" ID="txtSameAsMerchantBank" meta:resourcekey="lblSameAsMerchantBank"></asp:Label>

    <div id="divBankInformation" style="display: none;">
        <ABS:BankInformationGridView runat="server" ID="bankInformationGridView"/>
    </div>

What I'm trying to do is to invoke pop up window that is defined as UpdatePanel in BankInformationGridView control, but I need to do this from the DirectDebit control backend.

So I've decided to use RegisterClientScriptBlock method in the backend of DirectDebit:

protected void chkSameAsMerchantBank_CheckedChanged(object sender, EventArgs e)
{
    RegisterOpenDialogClientScript();
}
private void RegisterOpenDialogClientScript()
{
     ScriptManager.RegisterClientScriptBlock(bankInformationGridView, typeof(UpdatePanel), bankInformationGridView.ClientID, "OpenAddressDialog( '" + bankInformationGridView.ClientID + "' );", true);
}

My question is: Is there a way to access UpdatePanel control with ID: upBankInformationDirectDebit in the backend class of DirectDebit control by using instance of BankInformationGridView control that is in the hidden div of DirectDebit control and passing it as a paramether of RegisterClientScriptBlock method?

From the user side what I'm trying to accomplish is: If user deselects Same as merchant bank checkbox, pop up window with UpdatePanel should be shown.




Aucun commentaire:

Enregistrer un commentaire