send information to user control

G

Green

Hi,
I have an user control. And normally you can set the property of the user
control so as to send the information of the page to the user control like
below:
<TagPrefix: TagName id="***" property1="***" property2="***" ...> in the
aspx page, and in the user control you can pick those information up to do
something.
But it is kind of fixed solution. Can i dynamically do this?

My situation is:
I need to set a variant or property in the user control (ascx)
according to a value(in aspx) which will be decided at runtime of the aspx
page. How can i do this?

I appreciate in advance!!
 
S

Steven Cheng[MSFT]

Hi Green,

As for this problem, I thinkwe can just set the usercontrol's property at
runtime as
usercontrol.PropertyName = XXX;

And the keypoint is that we need to retrieve the UserControl's reference
and CAST the reference to the UserControl's Actual Type. We can use the
"FindControl" method to locate the UserControl from its parent Container
Control, for example:


========aspx page=============
<form id="Form1" method="post" runat="server">
<uc1:propertyControl id="pcOne" Title="MyTitle"
runat="server"></uc1:propertyControl>
</form>

=========code behind=====================
public class testpage1 : System.Web.UI.Page
{

private void Page_Load(object sender, System.EventArgs e)
{
HtmlForm form = this.FindControl("Form1") as HtmlForm;
PropertyControl pc = form.FindControl("pcOne") as PropertyControl;

pc.Title = "Changed Title";

}
.........
}

Hope helps.

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

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top