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

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

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

    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 Guest

  2. Similar Questions and Discussions

    1. making pop-ups work
      Hi, I'm scripting buttons in Flash MX to open HTML pop-up windows . I found the download example in the tutorials sections on how to script...
    2. CSS - Making content margins work for me
      Hello. I'm building a page that should fill the width of my browser window, with 3 pixels of space at the top, left, and right. If I use a...
    3. making XML::Parser work?
      I have downloaded and installed latest Expat. I have downloaded Expat.pm (and yeah if ou saw my post in .misc, I re-downloaded and it solved the...
    4. help with making media components work with flv
      I built a project in MX 6.0 that I published in a projector and burned to CD. It contained a number of swfs with embedded video clips which the user...
    5. Making a response form work
      Hi - I have inserted a form on my web site and configured it to send responses to my email address. But it doesn't work !!! When the submit...
  3. #2

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

    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
    >
    >
    >
    q@q.com Guest

  4. #3

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

    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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139