Results 1 to 9 of 9

Thread: Imagebutton in a usercontrol

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Helsingborg,Sweden
    Posts
    35

    Imagebutton in a usercontrol

    Hi!

    I have added a imagebutton on to a usercontrol. Here is the formcode
    HTML Code:
    <div style="WIDTH: 1000px; HEIGHT: 55px">
    		<table cellSpacing="3" cellPadding="3" width="1000" border="0">
    			<!--DWLayoutTable-->
    			<tr>
    				<td vAlign="top" width="24" height="24"><IMG height="24" alt="Ny kontakt" src="Images/Ikoner/ny.gif" width="24"></td>
    				<td vAlign="top" width="24"><a href="frmListContact.aspx"><IMG src="Images/Ikoner/Lista.gif" alt="Lista" width="24" height="24" border="0"></a></td>
    				<td vAlign="top" width="24">
    					<asp:ImageButton id="imgbSave" runat="server" ImageUrl="Images/Ikoner/Spara.gif"></asp:ImageButton></td>
    				<td vAlign="top" width="24"><IMG height="24" alt="Ta bort" src="Images/Ikoner/radera.gif" width="24"></td>
    				<td class="text" align="right" width="844">&nbsp;</td>
    			</tr>
    			<TR>
    				<TD vAlign="top" bgColor="#000000" colSpan="5" height="1"></TD>
    			</TR>
    			<TR>
    				<TD vAlign="top" bgColor="#ffffff" colSpan="5" height="1"><img src="Images/Ikoner/kundkort.gif" width="32" height="32" align="absMiddle">
    					<strong class="text style1">KUNDKORT</strong></TD>
    			</TR>
    		</table>
    	</div>
    Here is the codebehind code
    VB Code:
    1. Public Class ContactMenu
    2.     Inherits System.Web.UI.UserControl
    3.  
    4. #Region " Web Form Designer Generated Code "
    5.  
    6.     'This call is required by the Web Form Designer.
    7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    8.  
    9.     End Sub
    10.     Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    11.     Protected WithEvents imgbSave As System.Web.UI.WebControls.ImageButton
    12.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
    13.     'Do not delete or move it.
    14.     Private designerPlaceholderDeclaration As System.Object
    15.  
    16.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    17.         'CODEGEN: This method call is required by the Web Form Designer
    18.         'Do not modify it using the code editor.
    19.         InitializeComponent()
    20.     End Sub
    21.  
    22. #End Region
    23.  
    24.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    25.  
    26.     End Sub
    27.  
    28.     Public Sub imgbSave_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbSave.Click
    29.  
    30.         Dim obj As Contactcard = New Contactcard
    31.         Dim I As Integer = obj.Save_Contact()
    32.         If I = 1 Then
    33.  
    34.         End If
    35.     End Sub
    36.  
    37. End Class

    My problems is that the imgbSave_Click metod is not executed when i press the imagebutton.

    What´s wrong?

    /Tyson

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Imagebutton in a usercontrol

    Do you have form tags on your page, which is set to runat="server"?

  3. #3
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Imagebutton in a usercontrol

    Are you loading the usercontrol in your form on every postback? You need to do this to run the usercontrol's events.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Helsingborg,Sweden
    Posts
    35

    Re: Imagebutton in a usercontrol

    Yes I have formtags.

    Here is the code from the form that loads the usercontrol

    HTML Code:
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="frmContact.aspx.vb" Inherits="MW.frmContact"%>
    <%@ Register TagPrefix="SC" TagName="ContactCard" Src="Contactcard.ascx" %>
    <%@ Register TagPrefix="SC" TagName="ContactMenu" Src="ContactMenu.ascx" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    	<HEAD>
    		<title>Kontaktkort</title>
    		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    		<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
    		<meta content="JavaScript" name="vs_defaultClientScript">
    		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    		<LINK href="Body.css" type="text/css" rel="stylesheet">
    		<style type="text/css">.style1 { FONT-SIZE: 14px; COLOR: #ffffff }
    		</style>
    	</HEAD>
    	<body>
    		<form id="Form1" method="post" runat="server">
    			<table borderColor="#ece9d8" width="1000">
    				<!--DWLayoutTable-->
    				<tr bgColor="#000000">
    					<TD vAlign="top" colSpan="3" height="1"></TD>
    				</tr>
    				<tr vAlign="middle" bgColor="#006699">
    					<TD class="text" style="HEIGHT: 34px" width="660" height="34"><!--DWLayoutEmptyCell-->
    						&nbsp;<STRONG><FONT color="#ffffff" size="3">WebToMamut</FONT></STRONG></TD>
    					<TD class="text" style="HEIGHT: 34px" width="164"><!--DWLayoutEmptyCell--> &nbsp;<FONT color="#ffffff">Inloggad:</FONT></TD>
    					<TD width="151" class="text" style="HEIGHT: 34px" align="center"><!--DWLayoutEmptyCell--><asp:label id="Label1" runat="server" Font-Names="Verdana" Font-Size="8pt" ForeColor="White">Label</asp:label>&nbsp;</TD>
    				</tr>
    				<tr bgColor="#000000">
    					<TD vAlign="top" colSpan="3" height="1"></TD>
    				</tr>
    				</TR>
    				<tr>
    					<TD vAlign="top" colSpan="3"><SC:CONTACTMENU id="Contactcard1" runat="server"></SC:CONTACTMENU></TD>
    				</tr>
    				</TR>
    				<tr>
    					<TD vAlign="top" colSpan="3"><SC:CONTACTCARD id="Contact" runat="server"></SC:CONTACTCARD></TD>
    				</tr>
    			</table>
    			<BR>
    		</form>
    	</body>
    </HTML>
    
    
    so i guess that i load the usercontrol everytime.

    /tyson

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Imagebutton in a usercontrol

    Try this: Set AutoEventWireup="true" in the page directive.

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Helsingborg,Sweden
    Posts
    35

    Re: Imagebutton in a usercontrol

    I tried that and the page did load twice but no effect.

    You see! when i press the imagebutton the page that holds the usercontrol is reloaded. I added a breakpoint att the postback event. and the code steps over the ispostback because its true. then the page stops.

    dose this have something to do that the form how is holding the imagebutton is a user control?

    /Tyson

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Imagebutton in a usercontrol

    OK, I thought your page wasn't posting back either. Set autoeventwireup back to false, and place a breakpoint at the image button's click event, and follow it from there. What happens?

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Helsingborg,Sweden
    Posts
    35

    Re: Imagebutton in a usercontrol

    Quote Originally Posted by mendhak
    OK, I thought your page wasn't posting back either. Set autoeventwireup back to false, and place a breakpoint at the image button's click event, and follow it from there. What happens?
    i did that and nothing happends. I placed a breakpoint on the Image_click event and also at the page_load on the mainform. Al thats happend was that the code just step over the ispostback = false code in the mani form and stoped. It didn´t go to the Image button click eventet.

    /Tyson

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Helsingborg,Sweden
    Posts
    35

    Re: Imagebutton in a usercontrol

    I must be doing something wrong here, any ideas

    /tyson
    Knowledge rules!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width