Dynamically generating image buttons with text

  • Thread starter Thread starter CGuy
  • Start date Start date
C

CGuy

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
 
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


-----------------------------
 
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
 
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.
 
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.
 
Back
Top