Inserting Page variables into control's Text attribute in an aspx file

  • Thread starter Thread starter paul.hester
  • Start date Start date
P

paul.hester

Hi all,

I'm trying to display the a Page variable's value in the Text property
of a CheckBox control in the aspx file:

<asp:CheckBox ID="agreeTerms" Text="I agree to the <%# this.SiteName %>
terms and conditions" runat="server" />

I can do this elsewhere on the page, outside of a control, but in the
Text property it just renders the literal text: <%# this.SiteName %>
amongst the other text.

How can I achieve this in an aspx file, or do I have to set this
property in the code behind file?

Thanks,

Paul
 
I am not sure there is a way to combine variables with static text in the
*.aspx file for the Text property. I would suggest setting the Text property
in your code (probably immediately after you set the property). There might
be a way to do what you want using the (DataBindings) property (or whatever
the correct term for that box that you see above the (ID) property is, I'm
not sure if it is technically a property), but I have never used databinding
with anything other than databases and different collection types for
properties in controls that contain lists (such as DataList, DropDownList,
CheckBoxList, etc.), so I don't really know. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top