TheWizardofInt Posted August 17, 2006 Posted August 17, 2006 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 Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Administrators PlausiblyDamp Posted August 17, 2006 Administrators Posted August 17, 2006 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
TheWizardofInt Posted August 17, 2006 Author Posted August 17, 2006 Yes, I have been messing around with it and just copied it When it invokes the handler, it creates a button that does nothing when you click on it Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.