Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Replace text as server controls

Reply
Thread Tools

Replace text as server controls

 
 
Andla Rand
Guest
Posts: n/a
 
      05-22-2004
Hi,

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
server.

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

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

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.

Regards
Andla

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Eric Marvets
Guest
Posts: n/a
 
      05-22-2004
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 http://www.velocityreviews.com/forums/(E-Mail Removed) for Information on Our Architecture and
Mentoring Services

</shameless self promotion>


 
Reply With Quote
 
 
 
 
Andla Rand
Guest
Posts: n/a
 
      05-22-2004
Thanks for your answer it was helpful.

Regards
Andla

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Rajaram Mhadgut
Guest
Posts: n/a
 
      05-26-2004

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\"
value=\"Button\">");

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 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"
Text="Button"></asp:Button>
Response.write content_after_button




I think this will work fine .
But still u have any queries contact me.
Email me at (E-Mail Removed) .

Regards,
Rajaram Mhadgut



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression to Replace UPPER Case Text with lower case text penny Perl Misc 28 03-10-2008 01:14 AM
replace text in IFRAME using innerHTML.replace(...) possible? mscir Javascript 0 10-11-2005 11:21 PM
Difference in Web server Controls and HTML Server Controls =?Utf-8?B?c2lhag==?= ASP .Net 7 03-07-2005 07:15 PM
HTML Server Controls vs Web Server Controls brian ASP .Net Web Controls 1 01-24-2005 05:13 AM
replace instances of text on page with image or other text? juglesh Javascript 16 12-27-2004 04:14 AM



Advertisments