Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       'we want to be situationally dependent on which buttons we show
       Dim glob As globVars
       Dim but As System.Web.UI.WebControls.ImageButton
       Dim tblRow As TableRow
       Dim tblCell As TableCell
       Dim sImageUrl As String                     'this is the image url based on the contents of the folder

       glob = globVars.GetInstance

       sImageUrl = "~/images/" & glob.sImageFolder & "/buttons/"

       'go through each of the possible buttons in the table
       'if it is visible, add a row to the table and add a button for the row, in its only cell
       With tblButtons
           If glob.butHome.bVisible = True Then
               but = New System.Web.UI.WebControls.ImageButton
               but = BuildButton(sImageUrl & "N-Home.gif", "btnHome", glob.butHome.sReDirect)
               tblCell = New TableCell
               tblCell.Controls.Add(but)
               tblRow = New TableRow
               tblRow.Cells.Add(tblCell)
               tblButtons.Rows.Add(tblRow)
           End If
       End With

   End Sub
   Private Function BuildButton(ByVal sImageUrl As String, ByVal sID As String, ByVal sReDirect As String) As ImageButton

       Dim but As New System.Web.UI.WebControls.ImageButton

       sReDirect = "<script language='JavaScript'>window.open('" & sReDirect & "')</script>"
       With but
           .ID = sID
           .ImageUrl = sImageUrl
           .ToolTip = "Hello"
           .CommandName = "onClick"
           .CommandArgument = "alert('Bite me')"
           .EnableViewState = True
           '.Attributes.Add("onClick", sReDirect)

           AddHandler .Click, AddressOf imgButton_Click
       End With
     

       Return but
   End Function
   Private Sub imgButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
       
       Response.Write("The button was clicked")
   End Sub

 

Doesn't work

 

It creates the table, the row, the cell and the button, but clicking on the button does nothing.

 

I am about to use an image instead and wrap it with <a href=></a>, but wanted to see if I left something out first

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

  • Administrators
Posted

Not sure what is happening with

but = New System.Web.UI.WebControls.ImageButton
but = BuildButton(sImageUrl & "N-Home.gif", "btnHome", glob.butHome.sReDirect)

but the first of those two lines is redundant as you never use the instance of ImageButton that it creates.

 

If you put a breakpoint on the event handler is it ever reached?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...