Replace text as server controls

Discussion in 'ASP .Net' started by Andla Rand, May 22, 2004.

  1. Andla Rand

    Andla Rand Guest


    I would appreciate some directions on how to replace text as server
    controls. I'm currently reading text from a database and would like to
    build server logic based on specific information retrieved from the

    Here is some sample code that I'm currently playing with:

    string repl=spn.InnerHtml;
    repl=repl.Replace("[button]","<INPUT type=\"button\" id=\"btn\"

    As you se the [button] is replaced with a button but if I make this a
    server button then the server does not process the information as a
    server control and thus the client get the server code.

    I would appreciate any help on this.


    *** Sent via Developersdex ***
    Don't just participate in USENET...get rewarded for it!
    Andla Rand, May 22, 2004
    1. Advertisements

  2. Eric Marvets

    Eric Marvets Guest

    Sure you can.

    Step 1: Place an ASP.NET placeholder where the text will be rendered.
    Step2: Pase out the text before your button and do the following

    PlaceHolderX.Controls.Add(new LiteralControl(sTextBefore));
    PlaceHolderX.Controls.Add(new Button());
    PlaceHolderX.Controls.Add(new LiteralControl(sTextAfter));

    Now what happens on subsequent page requests will be your problem. You will
    need to create the controls on Post back in the same order as when they were
    shipped to the client, so the viewstate and events will tie back together.
    Before you ship the page to the client again, you are welcome to change the
    order or type of controls, but when the page is posted back again, they need
    to recreate them in the exact same order.

    Eric Marvets
    Principal Consultant

    the bang project

    <shameless self promotion>

    Email for Information on Our Architecture and
    Mentoring Services

    </shameless self promotion>
    Eric Marvets, May 22, 2004
    1. Advertisements

  3. Andla Rand

    Andla Rand Guest

    Thanks for your answer it was helpful.


    *** Sent via Developersdex ***
    Don't just participate in USENET...get rewarded for it!
    Andla Rand, May 22, 2004
  4. Hi Andla,

    This is Rajaram.

    As per my understanding u want to create server controls dynamically.
    But in first method u have created client side control by using
    statement :

    repl=repl.Replace("[button]","<INPUT type=\"button\" id=\"btn\"

    This will always works fine, since it process string and give code to
    client and this string contains plain HTML code which can be dispalyed
    by client browser, but now u want to display server control, If u used
    same way to display server control , It will generate output string
    which looks like server control code but since this code is already
    transfered to client browser and client browser can not recognise this
    code and display it as plain HTML code,
    To avoide this proble u need to create ur own server control which
    accpts string and create all dynamic server contorls.
    To generate server controls pls don't use replace method ,
    break input string and use if then conditions to add server control
    For eg:

    It is not actual code but u can understand what u have to do:

    If Instr(yourstr,"[Button]") <> -1 then
    button_pos = Instr(yourstr,"[Button]")
    content_before_button = left(yourstr,button_pos)
    content_after_button = left(yourstr,button_pos+ 8) ' 8 is used as length
    of string "[Button]"
    Response.write content_before_button
    ' and here is code to display server side button
    <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 92px; POSITION:
    absolute; TOP: 54px" runat="server" Width="207px" Height="39px"
    Response.write content_after_button

    I think this will work fine .
    But still u have any queries contact me.
    Email me at .

    Rajaram Mhadgut :)

    *** Sent via Developersdex ***
    Don't just participate in USENET...get rewarded for it!
    Rajaram Mhadgut, May 26, 2004
    1. Advertisements

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. =?Utf-8?B?c2lhag==?=
    Mar 7, 2005
  2. brian

    HTML Server Controls vs Web Server Controls

    brian, Jan 21, 2005, in forum: ASP .Net Web Controls
    Steve C. Orr [MVP, MCSD]
    Jan 24, 2005
  3. juglesh
    Dec 27, 2004
  4. penny
    Charlton Wilbur
    Mar 10, 2008
  5. mscir
    Oct 12, 2005

Share This Page