0

I have created a lot of asp:literal's inside a control (vehicle/finance-boxes.ascx)

<tr><td class="title">Deposit</td></tr>
<tr><td class="fig"><asp:Literal id="oneDeposit" runat="server"/></td></tr>
<tr><td class="fig"><asp:Literal id="twoDeposit" runat="server"/></td></tr>
<tr><td class="fig"><asp:Literal id="threeDeposit" runat="server"/></td></tr>

This control is being called to the page 'offer-finance.aspx'. (as well as ten others) I have done a lot of researching, but I can't seem to find or be told how I can define the ASP:Literals in the offer-finance.cs.aspx back end. ??

Please help, newbie in need of advice.

wilsonlego
  • 97
  • 1
  • 2
  • 15
  • This might be helpful to you http://stackoverflow.com/questions/4236650/how-to-create-a-usercontrol-that-you-can-drop-other-controls-in-it – MaxPayne Jun 24 '13 at 12:54

3 Answers3

2

You define properties in your user control's code-behind (finance-boxes.ascx.cs):

public string OneDeposit
{
    get { return oneDeposit.Text; }
    set { oneDeposit.Text = value; }
}

Then in your page (offer-finance.aspx) you add the control:

<whatev:FinanceBoxesControl ID="FinanceBoxes" runat="server" />

And in your page's code-behind, access it like any other control:

string OneDeposit = FinanceBoxes.OneDeposit;

Jason P
  • 26,984
  • 3
  • 31
  • 45
  • You were a little quicker and a lot more detailed than I. – Kevin DeVoe Jun 24 '13 at 12:52
  • Thanks @JasonP, would you advise putting 'string OneDeposit = FinanceBoxes.OneDeposit;' into the Page_Load. It's just it's erroring with _italic_Doesn't contain a definition for oneDepsoit_italic_ within offer-finance.cs ? – wilsonlego Jun 24 '13 at 13:26
  • You would put it wherever you need it. I would assume you would set the values of the textboxes in your control when the page loads, or read the values after the users clicks some kind of submit button. The point of that line was really just showing HOW you access the properties of the control (the `FinanceBoxes.OneDeposit` part). – Jason P Jun 24 '13 at 13:55
1

If you are trying to access the Literals from .aspx.cs, that is the code-behind file, you need to access it first, something like below

Literal oneDeposit=UserControlId.FindControl("oneDeposit") as Literal;
bazz
  • 613
  • 4
  • 10
0

You need to add a property to the control's code and then you can get and set the property from the pages that are using the user control.

Kevin DeVoe
  • 600
  • 2
  • 8