473,836 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with button control containing text and image

Hello all. I am trying to implement my first server control and have
run into two problems that I cannot solve. I need the assistance of
someone with more experience.

My goal was to create an input button that would allow for both text
and an image on it. I am attempting to accomplish this by basing off
of the asp:button control. I added a property for the image url and
one to determine if the image is displayed on the left or right of the
text. I am also overriding the necessary methods so that the html that
is rendered is correct. (The code is included below.)

In my aspx file I put two instances of the control:

<tlic:ImageText Button ID="btnSaveAll " runat="server" Text="Save All"
ImageUrl="Image s/Diskette.gif" />
<tlic:ImageText Button ID="btnEmailAll " runat="server" Text="Email All"
ImageUrl="Image s/Envelope.gif" OnClientClick=" return GetRecipients() ;"

It renders the following in the html to the browser:

<button type="submit" name="btnSaveAl l" value="Save All"
id="btnSaveAll" ><img id="btnSaveAll_ Img" name="btnSaveAl l:Img"
src="Images/Diskette.gif" border="0" />&nbsp;Save All</button>
<button type="submit" name="btnEmailA ll" value="Email All"
onclick="return GetRecipients() ;" language="javas cript"
id="btnEmailAll "><img id="btnEmailAll _Img" name="btnEmailA ll:Img"
src="Images/Envelope.gif" border="0" />&nbsp;Email All</button>

So far, all is good. The problems come in when I click one of the
buttons. The first problem is that ASP.NET complains when validating
the response because the value of the button is being returned as the
inner html rather than what is in the Value attribute. Since there is
an IMG tag there it thinks the data is suspect. Here is the form data:

__VIEWSTATE /wEPDwUKMTgzNj(s nip)...
gridAuthKeys:_c tl2:tbRANumber
gridAuthKeys:_c tl2:tbPONumber
gridAuthKeys:_c tl2:tbMustArriv eBy
btnSaveAll <IMG id=btnSaveAll_I mg src="Images/Diskette.gif" border=0
name=btnSaveAll :Img>&nbsp;Save All
btnEmailAll <IMG id=btnEmailAll_ Img src="Images/Envelope.gif" border=0
name=btnEmailAl l:Img>&nbsp;Ema il All

I figured I would deal with that later so I turned off page validation
to see if the rest of the processing would work. The second problem is
that no matter which button I click, ASP.NET fires off the event
handler for which ever is the last, or second, button, in this case
"email all". Again, I think the value of the button controls is
messing it up.

I tried setting the buttons to UseSubmit=False vs. True but that
didn't help. An interesting thing to note is that according to the
HTML spec, if a form contains more than one submit button, only the one
clicked is supposed to be included in the form data returned. This is
not what is happening here.

I would greatly appreciate any time that someone could spend to help me
with this.



Here is the code for the control:

Imports Microsoft.Visua lBasic
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Componen tModel
Imports System.Drawing. Design

Namespace TLI.Controls

''' <summary>
''' A control rendered as a button that has both an image and text.
''' </summary>
''' <remarks></remarks>
<ToolboxData("< {0}:ImageTextBu tton
runat=server></{0}:ImageTextBu tton>")_
Public Class ImageTextButton
Inherits WebControls.But ton

<Bindable(True) , _
Category("Appea rance"), _
DefaultValue("" ), _
Editor("System. Windows.Forms.I mageEditorIndex , System.Design",
GetType(UITypeE ditor)), _
Description("Th e image to appear on the button")_
Public Property ImageUrl() As String
Dim s As String = CStr(ViewState( "ImageURL") )
Return IIf(s Is Nothing, "", s)
End Get
Set(ByVal value As String)
ViewState("Imag eURL") = value
End Set
End Property

<Bindable(True) , _
Category("Appea rance"), _
DefaultValue(Tr ue), _
Description("Tr ue if the image is to appear to the left of the
Public Property ImageLeft() As Boolean
Dim o As Object = ViewState("Imag eLeft")
Return IIf(o Is Nothing, True, CBool(o))
End Get
Set(ByVal value As Boolean)
ViewState("Imag eLeft") = value
End Set
End Property

Protected Overrides ReadOnly Property TagKey() As
HtmlTextWriterT ag
Return HtmlTextWriterT ag.Button
End Get
End Property

Protected Overrides Sub RenderContents( ByVal writer As
System.Web.UI.H tmlTextWriter)
If ImageLeft Then
RenderImage(wri ter)
writer.Write("& nbsp;")
End If
writer.Write(Te xt)
If Not ImageLeft Then
writer.Write("& nbsp;")
RenderImage(wri ter)
End If
End Sub

Private Sub RenderImage(ByV al writer As
System.Web.UI.H tmlTextWriter)
writer.AddAttri bute(HtmlTextWr iterAttribute.I d, ID &
writer.AddAttri bute(HtmlTextWr iterAttribute.N ame, ID &
writer.AddAttri bute(HtmlTextWr iterAttribute.S rc, ImageUrl)
writer.AddAttri bute(HtmlTextWr iterAttribute.B order, "0")
writer.RenderBe ginTag(HtmlText WriterTag.Img)
writer.RenderEn dTag()
End Sub
End Class
End Namespace

Sep 7 '06 #1
0 1891

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

Similar topics

by: Christopher Brandsdal | last post by:
Hi! I have a anoying problem with my editor! What i want to do is make a popup that holds a string for the "hyperlink" window... I have a popup to do this before, and it works perfecty, but in order to make it work, I have to know the adress of the box I wanna put the value back in to... I have this so far :)
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
by: Gastin | last post by:
I am digesting a web serivce from Amazon.Com. I have the following class which was autogenerated by VS.NET when I created a Web Reference to http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl AmazonWebService.com.amazon.webservices.Item As you can see from the code snippets below it has public member variables rather than public Properties. When I use <%# DataBinder.Eval(Container.DataItem, "ASIN") %> syntax in...
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for some reason I keep getting the error: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
by: Andrew | last post by:
Hello Everyone I am receiving an error in an application I am working on. The application when its done will be a Dungeons and Dragons Network game. I am having problems with the Networked Canvas basically for drawing the dungeon maps If I initialize two of the Tkinter Canvas widgets with in the same window I can draw across the network, however if I open a second instance of the Application and initialize the canvas, on windows I recv
by: kombu67 | last post by:
I'm reading a series of images from a MS SQL table and saving them to directory. These are staff ID pictures from our security card app. Once I've extracted the ID photo from the security app to disk, I need to reference the disk file in our HR app. As part of the process, I'm resizing the image and changing its resolution from 96 to 72 dpi. If they are not at a 72 dpi resolution, the HR app freezes. The resizing works without a hitch, but...
by: hzgt9b | last post by:
I want a page with a centered div containing two rows. Top row has an image and some text. The bottom row needs to have three columns. I'd love to have the 1st column set to a fixed width then have the 2nd and 3rd columns fill the remaining space but I've given up on that and am willing to settle for the second row to have a fluid 3-column layout (or something else simple). Anyway, I've developed a page where the second row has this 3...
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...
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: 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: 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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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...

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.