Solved

Exposing properties of an ascx control so they can be set in the aspx element tag?

Posted on 2009-06-30
2
532 Views
Last Modified: 2012-05-07
I created a control ascx file. In its code behind file I added a public string called my_prop. I had hoped that when I declared an element of the type defined in my ascx file that I could set my_prop from the aspx tag. This doesn't seem to be the case, are there additional steps that need to be taken?
0
Comment
Question by:Matt_Du
2 Comments
 
LVL 15

Expert Comment

by:jinal
ID: 24751004
so you have .ascx like

public partial class Myascx : UserControl
{
    public string my_prop = string.empty;
}

No in aspx:

<uc1:Control ID="MyAscx1" my_prop="test" />

if you want like this then In

public partial class Myascx : UserControl
 {
     public string my_prop = string.empty;

    public string MYProp
    {
         get
         {
              return my_prop;
         }
         set
          {
                my_prop=  value;
          }
    }
 }

Declaration should be like
<uc1:Control ID="MyAscx1" MYProp ="test" />.

Overall idea is to create property.
0
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24751442
You should be able to use public variables in control declaration in aspx page like :
    <uc1:WebUserControl1 ID="myId" runat="server" my_prop="Print this text" />
 then on ascx.cs you can try to use that for example:

        public string my_prop;
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(my_prop);
        }

works perfectly, however VS intellisense doesn't recognize my_prop when writing control in aspx.

hope this helps.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now