Help with making a control work . Please help :-(

Discussion in 'ASP .Net Building Controls' started by Simon Harvey, Oct 20, 2004.

  1. Simon Harvey

    Simon Harvey Guest

    Hi everyone,

    I'm having a problem with getting a control that I'm using to work.

    I have a placeholder control sitting within a user control.

    On certain occasions at runtime I create a Textbox control and add it to the
    placeholder. This works well almost all the time.

    Unfortunately there is one scenario when it doesnt work. The textbox doesnt
    seem to be initialised whereas it normally is.

    Does anyone know why it should work sometimes but not others?

    I think its something to do with me needing to initialise the Textbox
    control myself. Could someone show me how to do that and where to put the
    code? I've tried just creating a new textbox, setting its Text and then
    adding it to the pages control collection. This just ends up adding a new
    textbox to the form :-(

    If anyone could help with this I would be very greatful. I've heard lots of
    people saying that you need to initialise your user controls manually but iv
    never seen a decent example of where and how to do it.

    Thanks

    Simon
     
    Simon Harvey, Oct 20, 2004
    #1
    1. Advertising

  2. Simon Harvey

    Guest

    Could you post your code for creating the TextBox
    & code for your Page_Load?

    Simon Harvey wrote:

    > Hi everyone,
    >
    > I'm having a problem with getting a control that I'm using to work.
    >
    > I have a placeholder control sitting within a user control.
    >
    > On certain occasions at runtime I create a Textbox control and add it to the
    > placeholder. This works well almost all the time.
    >
    > Unfortunately there is one scenario when it doesnt work. The textbox doesnt
    > seem to be initialised whereas it normally is.
    >
    > Does anyone know why it should work sometimes but not others?
    >
    > I think its something to do with me needing to initialise the Textbox
    > control myself. Could someone show me how to do that and where to put the
    > code? I've tried just creating a new textbox, setting its Text and then
    > adding it to the pages control collection. This just ends up adding a new
    > textbox to the form :-(
    >
    > If anyone could help with this I would be very greatful. I've heard lots of
    > people saying that you need to initialise your user controls manually but iv
    > never seen a decent example of where and how to do it.
    >
    > Thanks
    >
    > Simon
    >
    >
    >
     
    , Oct 20, 2004
    #2
    1. Advertising

  3. Simon Harvey

    Simon Harvey Guest

    Ok, thanks for your reply.

    If the textbox should be displayed, as determined on the first request to
    the page - I make a control and add it to the placeholder:

    txtUsername = new TextBox();
    txtUsername.ID = "txtUsername";
    txtUsername.BorderWidth = 1;
    txtUsername.BorderStyle = BorderStyle.Solid;
    phUsernamePlaceholder.Controls.Add(txtUsername);



    Later, if the situation is a postback I have:

    txtUsername = new TextBox();
    txtUsername.ID = "txtUsername";
    txtUsername.BorderStyle = BorderStyle.Solid;
    txtUsername.BorderWidth = new Unit(1);
    txtUsername.Text = Request.Form["createUserControl:txtUsername"];

    This now seems to be working but I'm not 100% sure why. Is this normally
    what you have to do with controls? Seems quite simple. You don't have to do
    anything special - just create a new txt box and make sure it has the same
    name as the one that should be on the page?

    Thanks

    Simon
     
    Simon Harvey, Oct 21, 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. Simon Harvey
    Replies:
    2
    Views:
    368
    Simon Harvey
    Oct 21, 2004
  2. Replies:
    5
    Views:
    1,939
    Andrew Thompson
    Jan 12, 2005
  3. Replies:
    4
    Views:
    565
    Chris Uppal
    May 5, 2005
  4. KK
    Replies:
    2
    Views:
    711
    Big Brian
    Oct 14, 2003
  5. Simon Harvey

    Help with making a control work . Please help :-(

    Simon Harvey, Oct 20, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    128
    Simon Harvey
    Oct 21, 2004
Loading...

Share This Page