question about an MS article of user control

G

Green

Hi,
I have a question concerning how to manipulate the properties in the user
control, and there is an interesting article about this from Microsoft:
http://msdn.microsoft.com/library/d...guide/html/cpconexposingpageletproperties.asp

My situation is i have a user control resides in the aspx page. And In
the aspx page's html, i set the following:
<ucl:myControl id="title" EditText="Add New Topic" ></ucl:myControl>

And in my control i declare:
protected System.Web.UI.WebControls.HyperLink EditButton;
public String EditText = null; // why use String instead of string
....

EditButton.Text = EditText;
....

Then i ran the program, the HyperLink button EditButton's text was set to
"Add New Topic". I just don't know how it works.(The article tell the
exactly the same technique.)
How come EditText will be automatically set to "Add New Topic"?
What i am thinking about is:
Then program first keep the value pair of EditText and "Add New Topic"
from the ucl section, then when run to the user section, it find the field
EditText and set it to the value provided in the ucl section. If i am wrong
please correct me.

I am more like to do the following way
protected System.Web.UI.WebControls.HyperLink EditButton;

public string EditButtonText{
get{return EditButton.Text;}
set{EditButton.Text = EditText;} // This is from the aspx's ucl
section.
}
public String EditText = null; // why use String instead of string
(if i set like: private String EditText = null; The program will not
locate it and set "Add New Topic to it, why?")
....

EditButton.Text = EditText;
....
 
S

Steven Cheng[MSFT]

Hi Green,

Thanks for posting here. As for the wonders you mentioned I'll try
explaining based on my understanding:

1. Why the example use "String" rather than "string"
=============================================
The "String" is just the System.String class which is the standard dotnet
framework class type. The "string" is System.String's alias in C# language(
just a keyword help to declare the System.String more convenient). They're
just the same one.

2. How does the value in <uc:Control attr= "value" > be assigned to the
actual control instance's field(property) at runtime.
=============================================
We can first discuss from the ASP.NET control's design-time support. Since
each control class may have
some properties or field and they support assignment at designtime. Then,
where do we store the assigned values ? As for the public property(fields),
the answer is just the control's inline attribute in the aspx page source.
For example:
<uc:Control Title="Title Text" ..>

The "Title Test" is just the value we assigned at design-time, and at
runtime, when the page is requested and intilizing, it will constructed the
Control class if there are such inline assignment:
Title="Title Text"
it will use this value to initialize the control's certain property/field.
This intializing is done before we can access the control on the page.
Sequence:
Parse aspx template file ---->Page init----> construct controls and set the
intial values from the inline values
------> other events we can handle(such as Page_load).


3. Why the inline setting not work if we change the public field into
private.
=============================================
This is a normal behavior since all the fields or properties we want to
expose to outer must declare as
public, otherwise, they're invisble to the Control's users.

Above are some of my understanding, if you have any other questions or
ideas, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Top