473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamically generating image buttons with text

Hi Gurus,

I have a rather unique requirements in my ASP.NET application - I need
to create image buttons on the fly while rendering a page.

The scenario is like this - the user can enter some text (max 10 chars)
in a page and when he saves the information, the next page should display an
imagebutton that has the text which the user entered (in the previous page).

Please help me with your valuable insights.

Regards,
CGuy
Nov 18 '05 #1
4 1862
looks like that attachement got stripped. Oh, well, all the better I
Suppose. Here is the code from the code behind on the generate.aspx file.
generate.aspx is just a blank file so it should be easy to re-create it.

--------------------------
Imports System
'Imports System.Collections
'Imports System.ComponentModel
'Imports System.Data
Imports System.Drawing
Imports System.Drawing.Imaging
'Imports System.Web
'Imports System.Web.SessionState
'Imports System.Web.UI
'Imports System.Web.UI.WebControls
'Imports System.Web.UI.HtmlControls

Namespace IRMWeb

Public Class Generator
Inherits Web.UI.Page

Private Sub Generator_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim objBitmap As Bitmap
Dim objGraphics As Graphics
Dim f As Font = New Font("Arial", 10, FontStyle.Regular)
Dim StrSize As System.Drawing.Size
Dim strText As String = Request("x")

If (strText.ToString.Length = 0) Then
' Create an Empty Image of 12 x 12 white
objBitmap = New Bitmap(12, 12)
objGraphics = Graphics.FromImage(objBitmap)
objGraphics.Clear(Color.White)
Response.End()
Return
Else
strText = strText.ToUpper

' Create Bitmap
objBitmap = New Bitmap(12, 12)

objGraphics = Graphics.FromImage(objBitmap)
StrSize = objGraphics.MeasureString(strText, f).ToSize()

' Initialize Graphics Class
objBitmap = New Bitmap(Convert.ToInt32(StrSize.Width -
(StrSize.Width * 0.07)), StrSize.Height)
objGraphics = Graphics.FromImage(objBitmap)
objGraphics.Clear(Color.White)
objGraphics.DrawString(strText, f, Brushes.Blue, 0, 0)

' Display Bitmap
Response.Buffer = True
Response.Clear()

objBitmap.Save(Response.OutputStream, ImageFormat.Gif)

Response.Flush()
Response.End()
End If
End Sub
End Class
End Namespace
-----------------------------

"Bob Boran" <mc*******@hotmail.com> wrote in message
news:#B**************@TK2MSFTNGP11.phx.gbl...
Here is a little aspx file I wrote about a year ago. It generates a small
image based on a text string passed to the page.

to use it you might do something like this on the page

<img src="generator.aspx?x=Bob">

this tag would generate an image on the fly that just says Bob
"CGuy" <cg**@csharp.net> wrote in message
news:eq**************@tk2msftngp13.phx.gbl...
Hi Gurus,

I have a rather unique requirements in my ASP.NET application - I need to create image buttons on the fly while rendering a page.

The scenario is like this - the user can enter some text (max 10 chars)
in a page and when he saves the information, the next page should

display an
imagebutton that has the text which the user entered (in the previous

page).

Please help me with your valuable insights.

Regards,
CGuy


Nov 18 '05 #2
TJS
your sample throws this error

Parser Error Message: Could not load type 'ZIA.IRMWeb.Generator'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false"
Codebehind="generator.aspx.vb" Inherits="ZIA.IRMWeb.Generator"%>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <HTML>

Source File: ...\generator.aspx Line: 1

"Bob Boran" <mc*******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Here is a little aspx file I wrote about a year ago. It generates a small
image based on a text string passed to the page.

to use it you might do something like this on the page

<img src="generator.aspx?x=Bob">

this tag would generate an image on the fly that just says Bob
"CGuy" <cg**@csharp.net> wrote in message
news:eq**************@tk2msftngp13.phx.gbl...
Hi Gurus,

I have a rather unique requirements in my ASP.NET application - I need to create image buttons on the fly while rendering a page.

The scenario is like this - the user can enter some text (max 10 chars)
in a page and when he saves the information, the next page should

display an
imagebutton that has the text which the user entered (in the previous

page).

Please help me with your valuable insights.

Regards,
CGuy


Nov 18 '05 #3
I apologize. There is a namespace issue.
The easiest way to fix it is to create a new generator.aspx page, then
replace the new code behind with the code behind I posted. That ought to
take care of it.

"TJS" <no****@here.com> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
your sample throws this error

Parser Error Message: Could not load type 'ZIA.IRMWeb.Generator'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false"
Codebehind="generator.aspx.vb" Inherits="ZIA.IRMWeb.Generator"%>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <HTML>

Source File: ...\generator.aspx Line: 1

"Bob Boran" <mc*******@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Here is a little aspx file I wrote about a year ago. It generates a small
image based on a text string passed to the page.

to use it you might do something like this on the page

<img src="generator.aspx?x=Bob">

this tag would generate an image on the fly that just says Bob
"CGuy" <cg**@csharp.net> wrote in message
news:eq**************@tk2msftngp13.phx.gbl...
Hi Gurus,

I have a rather unique requirements in my ASP.NET application - I

need to create image buttons on the fly while rendering a page.

The scenario is like this - the user can enter some text (max 10

chars)
in a page and when he saves the information, the next page should

display
an
imagebutton that has the text which the user entered (in the previous

page).

Please help me with your valuable insights.

Regards,
CGuy



Nov 18 '05 #4
Have you been able to add text without having to use an 'aspx' url? I am looking for some way to just send a bitmap in memory or use the Graphics classes to generate text directly to the ImageButton.
Nov 18 '05 #5

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

Similar topics

32
by: Mark Johnson | last post by:
You have an, a, anchor with href link. Can you use a stylesheet to effectively disable the link, so that you can't click on it; that it will appear simply as text?
7
by: Mark | last post by:
Hi, I am trying to create a "print preview" window for a web site using asp.net. I have got a long way down the road to the solution but the problem I have now is that the text and lines on the...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
1
by: PeteBr | last post by:
I am dynamically generating a number of button controls based on the results returned from a search carried out on another machine. When one of these buttons is selected I want to be able to go...
2
by: ghadley_00 | last post by:
Hi, I have a database with a main table and a lookup table of customers, and reports for each of the customers listing each transaction they have listed. I have a form that has buttons for...
2
by: Patrick | last post by:
Hello, I have an ASP page, where I want to add buttons dynamically. I used C# and a for-loop do to this. The button generating code looks like this: Button bt1 = new Button(); bt1.Text =...
0
by: krish | last post by:
hi, I am dynamically generating Imagebutton (say 5 imagebutton, in loop) . for each imagebutton url , i am dynamically generating image and assigining to it. every thing is ok upto this...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.