I'm attempting to programmaticall y build up some HTML in the code
behind. Like so:
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
link.Text = "Cats Sleeping";
//Create Image
Image img = new Image();
img.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
//Add image nested in the hyperlink
link.Controls.A dd(img);
//Add the link with it's controls to a placeholder
PlaceHolder1.Co ntrols.Add(link );
When I run the code I'm expecting an picture of a cat with the text
'Cats Sleeping' all enclosed in anchor tags. But instead all I get is
the image but no text. What am I doing wrong? 4 4121
What's probably happening is the image is replacing the text since they
technically want to fill the same spot. Instead of setting the text property
of the link, try doing something like creating the text as a literal then
adding the literal to the link's control collection.
Literal myText = new Literal();
myText.Text = "Cats Sleeping";
link.Controls.A dd(myText);
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
<al****@gmail.c omwrote in message
news:f0******** *************** ***********@v4g 2000hsf.googleg roups.com...
I'm attempting to programmaticall y build up some HTML in the code
behind. Like so:
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
link.Text = "Cats Sleeping";
//Create Image
Image img = new Image();
img.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
//Add image nested in the hyperlink
link.Controls.A dd(img);
//Add the link with it's controls to a placeholder
PlaceHolder1.Co ntrols.Add(link );
When I run the code I'm expecting an picture of a cat with the text
'Cats Sleeping' all enclosed in anchor tags. But instead all I get is
the image but no text. What am I doing wrong?
Hi,
You would need to make the Hyperlink control as the container to show both
the text and image control in the Hyperlink control because this is the
default behavior of the Hyperlink control to replace the text with the image.
protected void Page_Load(objec t sender, EventArgs e)
{
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
//link.Text = "Cats Sleeping";
//link.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
Label lb = new Label();
lb.Text = "Cats Sleeping";
link.Controls.A dd(lb);
//Create Image
Image img = new Image();
img.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
//Add image nested in the hyperlink
link.Controls.A dd(img);
//Add the link with it's controls to a placeholder
PlaceHolder1.Co ntrols.Add(link );
}
Regards,
Manish www.ComponentOne.com
"Mark Fitzpatrick" wrote:
What's probably happening is the image is replacing the text since they
technically want to fill the same spot. Instead of setting the text property
of the link, try doing something like creating the text as a literal then
adding the literal to the link's control collection.
Literal myText = new Literal();
myText.Text = "Cats Sleeping";
link.Controls.A dd(myText);
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
<al****@gmail.c omwrote in message
news:f0******** *************** ***********@v4g 2000hsf.googleg roups.com...
I'm attempting to programmaticall y build up some HTML in the code
behind. Like so:
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
link.Text = "Cats Sleeping";
//Create Image
Image img = new Image();
img.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
//Add image nested in the hyperlink
link.Controls.A dd(img);
//Add the link with it's controls to a placeholder
PlaceHolder1.Co ntrols.Add(link );
When I run the code I'm expecting an picture of a cat with the text
'Cats Sleeping' all enclosed in anchor tags. But instead all I get is
the image but no text. What am I doing wrong?
On 16 Січ, 07:07, alu...@gmail.co m wrote:
I'm attempting to programmaticall y build up some HTML in the code
behind. Like so:
// Create Hyperlink
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
link.Text = "Cats Sleeping";
//Create Image
Image img = new Image();
img.ImageUrl = "http://www.cats.org.uk/images/lhstop_home2.jp g";
//Add image nested in the hyperlink
link.Controls.A dd(img);
//Add the link with it's controls to a placeholder
PlaceHolder1.Co ntrols.Add(link );
When I run the code I'm expecting an picture of a cat with the text
'Cats Sleeping' all enclosed in anchor tags. But instead all I get is
the image but no text.
Try this:
HyperLink link = new HyperLink();
link.NavigateUr l = "nice cat";
link.Text = string.Format(" <img src='{0}'><br>{ 1}", "http://
www.cats.org.uk/images/lhstop_home2.jp g", "Cats Sleeping");
PlaceHolder1.Co ntrols.Add(link );
Regards,
Mykola http://marss.co.ua - Casual ideas for web development
Thanks for both your great answers, that's excatly what's been
happening. And thanks for the bit of code Manish I'll use it. Many
thanks Again This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: V. Jenks |
last post by:
What seems like a simple thing is apparently not so
straightforward?
I have a datalist.
Inside of that datalist is an <itemtemplate> secion which
contains other server controls such as a label, a
radiobuttonlist, etc.
I'm driving myself insane trying to figure out how to get
|
by: D Sheldon |
last post by:
I am creating a server control that adds web controls (i.e. textboxes, etc) to a form. I use HtmlTable to build the table and insert the controls. Now I want to add validators to the textbox. Here is the code that I am using
bool lastnamerequired=false
public bool LastNameRequire
get{return lastnamerequired;
set{lastnamerequired = value;
if(lastnamerequired
|
by: Andla Rand |
last post by:
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;
|
by: clintonG |
last post by:
Technically speaking, this issue is not about modifying the HTML
generated by server controls but preceding the HTML generated by
server controls with an HTML control generated on the basis of the
type and the context of the server control itself. Clear as mud? :-)
Consider the following server control...
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>
TextBox renders at run-time as an HTML control...
<input...
|
by: Patrick |
last post by:
I want to define a set of web-form templates in XML and render the equivalent
web-form with ASP.NET, then process any input server controls on the form.
Reading the XML file from Page_load is easy, but
1) How do I set about dynamically creating user controls (like TextBox,
TextArea)
--- simply Declare and initialised (new) the user controls?? How do I
"place" it graphically on the form. Ideally, I want them to lay out in a
table, one...
| |
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...
|
by: Mr Newbie |
last post by:
I was thinking about developing a workflow application yesterday and was
musing over the different approaches than one could take in restricting
specific actions on a ticket( Form ) at any said stage.
One approach I have used on other systems is to prevent the action buttons
appearing. For example, if one did not have the Role of Administrator, one
would be prevented from deleting a ticket not created by oneself.
However, it did occur...
|
by: z f |
last post by:
hi, tough one? for me it is currently.
i have a user control that contains other controls like text boxes.
in the client i need to dynamically add the user control using DHTML.
i achive this by having the control hidden and grabbing it's innerHTML to a
new container in the HTML.
i also change controls ID suffix in order to be able to track added controls
like in old HTML.
|
by: sean_mcad |
last post by:
We are starting to standardize what we have been doing with our web
applications and I have a “cost-benefit” question when it comes to some
server controls.
Main two examples is
Plain text vs. <asp:label /and <divvs <asp:panelsfor current static
information.
In my view if we go ahead and make all things static into server controls
anyway then we have the advantage of things like localization, skins and
|
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 projectplanning, coding, testing, and deploymentwithout 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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |