473,659 Members | 2,632 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.InnerH tml;
repl=repl.Repla ce("[button]","<INPUT type=\"button\" id=\"btn\"
value=\"Button\ ">");
spn.InnerHtml=r epl;

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 2049
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.Co ntrols.Add(new LiteralControl( sTextBefore));
PlaceHolderX.Co ntrols.Add(new Button());
PlaceHolderX.Co ntrols.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***@bangproje ct.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.Repla ce("[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,bu tton_pos)
content_after_b utton = left(yourstr,bu tton_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_b utton


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
8153
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 that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great...
2
1647
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 = replace(a,",","x",1,1) Response.write(replace(z,",","y")) I'm thinking regular expressions are the way to go but in use it will have
14
2329
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 read an xml file and, using the values retrieved from it, determine what text should be displayed and which controls should be rendered and - most importantly - where those controls should be rendered. The ultimate goal is to have some text...
5
4762
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 google can index it. Here is a specific example of what I want to do: <div id=SomeText> Here is some text. I went to the baseball game </div>
13
18385
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 carriage returns, with an html <br> tag. I tried the following function but it doesn't work. Does anyone have any ideas how to accomplish this? Thanks in advance. ~ CK string getComments()
1
1279
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 method=post runat="server"> <asp:label id=Label1 runat="server"/><BR> <asp:Label id=Label2 runat="server"/><BR> <asp:Button id=Button1 runat="server" Text="Button"/><BR> <asp:Button id=Button2 runat="server" Text="Button"/><BR> <asp:Button id=Button3...
1
2826
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 replace function to replace some text in the results. Access' REPLACE function is only available if executed within the environment, as it's a VBA function, not a SQL function. So how can I implement this is the EASIEST possible way? I don't to...
0
2864
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 , these values are displaying in next page.after displaying in next page, when click back button to see my entered values for change , no values are in the form fields. the fields are empty .I tried with enable view state=true in controls and at the...
1
3387
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. The problem is when it creates transparent PNG format image then and it pixel ate the image. e.g. If i am using a gradient in background then it vary in color range. Now when i used that php script it generates image successfully but it pixel ate...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2759
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 we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.