473,508 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace text as server controls

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!
Nov 18 '05 #1
3 2040
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 sa***@bangproject.com for Information on Our Architecture and
Mentoring Services

</shameless self promotion>
Nov 18 '05 #2
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!
Nov 18 '05 #3

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) ' 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 mh************@hotmail.com .

Regards,
Rajaram Mhadgut :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8132
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
2
1643
by: Roland Hall | last post by:
I have a little test that replaces the same character with two different values. Currently I have to process it twice. Is it possible to do it all at once? dim a, z a = "a,b,c" z =...
14
2299
by: Joe | last post by:
Hello All: I am trying to dynamically populate a web page with literal content and controls (textboxes and checkboxes (and eventually two buttons - the buttons do not appear in the code yet). I...
5
4746
by: Casey | last post by:
Hello, Can someone give me specific code to replace text on a page using server side javascript? I need to use server-side because I need the output to be recognized in the final HTML so that...
13
18331
by: CK | last post by:
Hi all, I have a textarea control. I am putting it's value in an html email. The problem is that the new lines are being ignored. I want to take the controls value and replace any newline...
1
1273
by: TH | last post by:
Could anyone please explain the bizarre and utterly infuriating effect I am observing while adding controls programmatically? I've reduced the problem to the following code: <form id=Form1...
1
2824
by: seanmatthewwalsh | last post by:
Hi I have a website that uses an Access 2003 database. I have controls on my pages that are bound to SqlDataSources that pull data from this database. In a couple of them, I need to use the...
0
2851
by: chandrasekhar | last post by:
Hi I have developed a web page with some controls. I put all of them in session variables. I passed this values in the page. When an user enter some data in form fields and click the buttton ,...
1
3377
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.