Link to home
Start Free TrialLog in
Avatar of LISCNY
LISCNY

asked on

Why doesn't my LinkButton on an Inherited ASPX Page fire?

I created a new aspx page (Download.aspx), which inherits from another aspx page (PageApp.aspx).  I added controls such as buttons and LinkButtons.  The click_event routine for the button gets fired w/ no problem, however, the LinkButton click_event does not fire when the inheritance of PageApp is used.  When I comment out the PageApp inheritence and inherit from System.Web.UI.Page, the click_event fires up successfully.  
Please note that the same PageApp is inherited in various other aspx pages in the same project where the linkButtons are used and they're working fine.  

Note, I added the LinkButton by dragging the control on the page and double-clicked on the link to generate the click_event routine.  Again, the routine excutes with the inheritence of Web.UI.Page.

I am stuck with this problem for a day but hitting the wall at this point.  I really appreciate all your help on this.  Thank you so much.
ASKER CERTIFIED SOLUTION
Avatar of McExp
McExp
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LISCNY
LISCNY

ASKER

No, it's set to false.
this is telling your page that you don't want any help with wiring up the events. if you need them to be off you need to add things like: -

Page.Load +=new EventHandler(Page_Load);  

It's simpler to set the AutoEventWireup to true.
Avatar of LISCNY

ASKER

I set the AutoEventWireup = true for both the download.aspx and pageApp.aspx files, but still cannot get the LinkButton event to fire.

My PageApp that's inherited in Download.aspx looks like this:


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="PageApp.aspx.vb" Inherits="PageApp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>PageApp</title>
		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
	</HEAD>
	<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">
		<form id="Form1" method="post" runat="server">
		</form>
	</body>
</HTML>

Open in new window

Is your Download.aspx and PageApp.Aspx both pointing at the same vb CodeBehind file?
Avatar of LISCNY

ASKER

No,
Download.aspx --> Download.aspx.vb
PageApp.aspx --> PageApp.aspx.vb
Ok, I was a little confused by your code snippit, that's all you have Codebehind="PageApp.aspx.vb" Inherits="PageApp", yet you claimed it was Download.aspx.

Could you post the aspx and vb file for the page you are having problems with.
Avatar of LISCNY

ASKER

Here's the code for Down.aspx.vb:
Public Class Down
    Inherits PageApp
 
#Region " Web Form Designer Generated Code "
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
 
    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub
 
#End Region
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not IsPostBack Then
            '	Me.__InitializeWebGrid()
            'me.TextBox1.Text.
 
        End If
    End Sub
 
    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim str As String
        Me.Label2.Text = "This Should Work"
    End Sub

Open in new window

Avatar of LISCNY

ASKER

Here's the code for the Down.aspx file:
<%@ Page Language="vb" AutoEventWireup="true" Codebehind="Down.aspx.vb" Inherits="beta.Down" enableViewState="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>Down</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">
	</HEAD>
	<body bottomMargin="1" leftMargin="1" rightMargin="1" MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<TABLE id="Table1" style="Z-INDEX: 103; LEFT: 8px; POSITION: absolute; TOP: 8px" height="90%"
				cellSpacing="0" cellPadding="0" width="90%" border="0">
				<TR>
					<TD style="HEIGHT: 14px"></TD>
				</TR>
				<TR>
					<TD style="HEIGHT: 132px" align="left">
						<TABLE id="Table2" cellSpacing="0" cellPadding="0" width="90%" border="0">
							<TR>
								<TD style="WIDTH: 54px; HEIGHT: 17px" align="left"></TD>
								<TD style="HEIGHT: 17px" align="center"><asp:label id="Label1" runat="server" forecolor="White" height="10px" backcolor="#1F3877" width="100%"
										font-names="Arial" font-size="9pt" font-bold="True">Download RPA</asp:label></TD>
							</TR>
							<TR>
								<TD style="WIDTH: 54px" align="left"></TD>
								<TD align="left">
									<asp:LinkButton id="LinkButton1" runat="server">Should work</asp:LinkButton></TD>
							</TR>
							<tr style="FONT-SIZE: 5pt">
								<td style="WIDTH: 1px; HEIGHT: 6px">
									<div style="DISPLAY: inline; WIDTH: 8px; HEIGHT: 5px" ms_positioning="FlowLayout"></div>
								</td>
							</tr>
							<TR>
								<TD style="WIDTH: 54px; HEIGHT: 20px" align="left"></TD>
								<TD style="HEIGHT: 20px" align="left"></TD>
							</TR>
							<TR>
								<TD style="WIDTH: 54px" align="left"></TD>
								<TD align="left"></TD>
							</TR>
							<TR>
								<TD style="WIDTH: 54px" align="left"></TD>
								<TD align="left">
									<asp:Label id="Label2" runat="server">Label</asp:Label></TD>
							</TR>
							<TR>
								<TD style="WIDTH: 54px" align="left"></TD>
								<TD align="left"></TD>
							</TR>
							<TR>
								<TD style="WIDTH: 54px" align="left"></TD>
								<TD align="left"></TD>
							</TR>
						</TABLE>
					</TD>
				</TR>
				<TR>
					<TD align="center"></TD>
				</TR>
				<TR>
					<TD align="center"></TD>
				</TR>
			</TABLE>
		</form>
	</body>
</HTML>

Open in new window

Avatar of LISCNY

ASKER

FYI, I also found the following code being executed in the page_load event in PageApp.aspx.vb everytime I navigate to a page that inherits PageApp class and that includes the Down.aspx page as well.
Private Sub __RegisterClientScript()
        Dim scriptUrl As String
        If Me.IsRegisterGeneric Then
            scriptUrl = vbCrLf + "<script language=""javascript"" src=""" + URLS.JSGeneric + """></script>"
            Me.RegisterClientScriptBlock("generic_js", scriptUrl)
        End If
 
        If Me.IsRegisterPHTE Then
            scriptUrl = vbCrLf + "<script language=""javascript"" src=""" + URLS.JSTransition + """></script>"
            Me.RegisterStartupScript("transition_js", scriptUrl)
        End If
 
        If Me.IsRegisterDefault Then
            scriptUrl = vbCrLf + "<script language=""javascript"" src=""" + URLS.JSDefault + """></script>"
            Me.RegisterStartupScript("default_js", scriptUrl)
        End If
 
        If URLS.IsDebug Then
            scriptUrl = vbCrLf + "<script language=""javascript"" src=""" + URLS.JSDebug + """></script>"
            Me.RegisterStartupScript("debug_js", scriptUrl)
        End If
    End Sub

Open in new window

I think your in your Down.aspx.vb class definition is not right, try changing: -

Public Class Down
    Inherits PageApp

to

Partial Class Down
    Inherits PageApp

The way ASP.NET 2.0 works (when using code behind) is that your page provides half the class and the .vb file provides the other half, hence the partial definition. these are then combined into one class for compilation. I'm not sure exactly what happens when you don't use a partial class but I'd guess that it will fail!
Avatar of LISCNY

ASKER

I found a workaround to this problem for now.  I copied another working page that contains linkButtons and inherits PageApp and renamed it and modified it according to my needs.  All of the working pages use PUBLIC definition.

I'm not exactly sure what's causing this issue but my inclination is that it's the javascript code that's limiting this.  I'm a windows developer so I still have to learn how to debug javascript code to get the full picture.  

Thanks a lot for all your time and assistance.
I've done some more research and it looks like you only need to use partial classes if you are working with the .20 Framework.

I'm assuming your not?
Avatar of LISCNY

ASKER

No, I'm not using 2.0
Tags: Microsoft, .NET, 1.1, ASP.NET and VB.NET - codebehind
yea, should have spotted that.

I've been working with the 2.0 framework for the last 18 months so i've kinda forgotten all about 1.1
Avatar of LISCNY

ASKER

It's okay, I know what you mean.  I like 2.0 better than 1.1 so when I switch back to coding in 1.1, I take a lot of features for granted and forget that the older version does not have them.  Thank you for your time.