开发者

Manipulating a control in a child from the parent page

开发者 https://www.devze.com 2023-03-16 03:01 出处:网络
The answer is probably obvious but I have not seen an开发者_如何学JAVAything I could use except the opposite - manipulating the parent from the child - so I\'m posting new.

The answer is probably obvious but I have not seen an开发者_如何学JAVAything I could use except the opposite - manipulating the parent from the child - so I'm posting new.

I have a shopping cart system I'm working on that my company purchased and I'm new to .NET so I may not even ask this properly.

My store has a page in the checkout portion that looks basically like this:

PaymentPage.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PaymentPage.ascx.cs" Inherits="ConLib_PaymentPage" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register Src="~/Checkout/PaymentForms/CreditCardPaymentForm.ascx" TagName="CreditCardPaymentForm" TagPrefix="uc" %>
<ajax:UpdatePanel ID="PaymentAjax" runat="server">
    <ContentTemplate>

            On page controls, etc.
            Then a checkbox saying they've read the terms and agree:
    <div id="terms">
        <asp:CheckBox ID="AgreeTerms" runat="server" Text="I agree to the Terms Of Service" CssClass="Terms" AutoPostBack="True" OnCheckedChanged="AgreeTerms_Clicked"/>
    </div>

The task I want to accomplish is in the OnCheckedChanged event I want to enable or disable an imagebutton inside the CreditCardPaymentForm control.

That code looks like this:

<%@ Control Language="C#" ClassName="CreditCardPaymentForm" EnableViewState="false" %>
<%@ Register Assembly="CommerceBuilder.Web" Namespace="CommerceBuilder.Web.UI.WebControls" TagPrefix="cb" %>
<%@ Register assembly="wwhoverpanel" Namespace="Westwind.Web.Controls" TagPrefix="wwh" %>

... a <script> block with some code and then HTML

<span class="TTAActionButton">
    <br>
    <asp:ImageButton ID="CreditCardButton" runat="server" ToolTip="Pay With Card" SkinID="TTAPlaceOrder" OnClick="CreditCardButton_Click" />
    <asp:HiddenField runat="server"  ID="FormIsSubmitted" value="0" />
    <br /><br /><br />
</span>

I want to be able to turn the CreditCardButton on and off depending on whether the checkbox is checked. I would have a routine in the page codebehind like:

public void AgreeTerms_Clicked(object sender, EventArgs e)
{
    if (AgreeTerms.Checked)
        CreditCardButton.Enabled = false;
}

but every permutation of that I try has failed.

I have abbreviated the code but if I've left out too much please let me know.

Thanks for your help and if you assume I know nothing about .NET then double-thanks! Jim


In the CreditCardPaymentForm control create a property that exposes the CreditCardButton visibility and than use that from the parent in the OnCheckedChanged function handler.

public bool ShowCreditCardButton
{
   get { return CreditCardButton.Visable; }
   set { CreditCardButton.Visable = value; }
}


Does CreditCardPaymentForm include a PaymentPage.ascx? That is, does the form 'use' the PaymentPage user control?

if so, your best bet it is to publish an event on PaymentPage that is raised by the checking of the checkbox:

public void AgreeTerms_Clicked(object sender, EventArgs e)
{
    if (AgreeTerms.Checked)
        OnTermsAgreed();
}

private void OnTermsAgreed()
{
    // raise TermsAgreed event
    var evt = TermsAgreed;
    if (null != evt)
        evt(this, EventArgs.Empty);
}
public event EventHandler TermsAgreed;

Then CreditCardPaymentForm subscribes to that event and 'does its thing' which in your case is to enable the button it knows about.

0

精彩评论

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