send information to user control

Discussion in 'ASP .Net' started by Green, Sep 21, 2004.

  1. Green

    Green Guest

    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!!
    Green, Sep 21, 2004
    #1
    1. Advertising

  2. Green

    Juno Guest

    Hi,

    You use
    yourcontrol.property1="****"
    yourcontrol.property2="****"
    in your code.

    --
    Juno
    MCSD.NET, MCDBA, MCSE
    ----------------------------------------------------------
    Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
    DataForm.NET - The most powerful data entry web server control for ASP.NET



    "Green" <> wrote in message
    news:...
    > 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!!
    >
    >
    Juno, Sep 21, 2004
    #2
    1. Advertising

  3. 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.)
    Steven Cheng[MSFT], Sep 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z. f.
    Replies:
    0
    Views:
    667
    z. f.
    Feb 3, 2005
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    622
    Mad Scientist Jr
    Mar 22, 2006
  3. =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?=

    Send credentials/user information accross applcations securely?

    =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?=, Sep 11, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    479
    =?Utf-8?B?RGFuaWVsIERpIFZpdGE=?=
    Sep 11, 2006
  4. Eric Layman
    Replies:
    3
    Views:
    562
    sloan
    May 10, 2007
  5. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    525
    Jonathan Wood
    Feb 2, 2010
Loading...

Share This Page