Solved

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

Posted on 2009-06-30
2
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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