user290043
user290043

Reputation:

Issue with code behind ASPX

I have an ASPX file with this button:

<asp:button id="cmdPartnerInfo" runat="server" Font-Bold="True" 
    Text="Partner Info" TabIndex="3">
</asp:button>

And in the ASPX.VB file I have this Sub:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    cmdPartnerInfo.Attributes.Add("onclick", "return ShowPartnerContatcInfo();")
    imgStaff.Attributes.Add("onclick", "return AddStaffSelection();")
    lblDt.Text = ""

... snip ...

End Sub

However, there is a squiggly line under cmdPartnerInfo and the message is:

Error 38 'cmdPartnerInfo' is not declared. It may be inaccessible due to its 
protection level.

So it looks like the code in the vb file doesn't see the asp control in the aspx page.

Any help figuring out why this is happening is appreciated.

Thanks! Eric

UPDATE: These are the two directives at the top of the ASPX page.

<%@ Register TagPrefix="Card" TagName="Banner" Src="~/banner.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false" CodeFile="projectpartlog.aspx.vb" Inherits="Project_and_Partners_Log" %>

Upvotes: 2

Views: 1615

Answers (5)

EdSF
EdSF

Reputation: 12351

<%@ Page Language="vb" AutoEventWireup="false" CodeFile="projectpartlog.aspx.vb" Inherits="Project_and_Partners_Log" %>

This directive means:

  1. The file name for your "code behind" should be projectpartlog.aspx.vb
  2. The Class name in the projectpartlog.aspx.vb file should be Project_and_Partners_Log

    Partial Class Project_and_Partners_Log
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub cmdPartnerInfo_Click(sender As Object, e As System.EventArgs) Handles cmdPartnerInfo_Click.Click     
    
          'Code.....
    
         End Sub
    
    End Class
    

Upvotes: 1

Eugene Trofimenko
Eugene Trofimenko

Reputation: 1631

  1. Check page's directive <%@ Page and ensure that you behind class belongs to you aspx file.
  2. Next issue which you need to check is aspx.designer file(you should find your Button control declaration). Sometimes VS doesn't add declaration automatically, when you copy-paste a code.

Upvotes: 3

David East
David East

Reputation: 32604

You need to check your page directive.

<%@ Page Language="VB" MasterPageFile="~/Master/Mater.master" AutoEventWireup="false"
    CodeFile="Test.aspx.vb" Inherits="Test" %>

Check to see if the CodeFile property is set to the proper code file.

Upvotes: 0

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28548

I think you have converted your button to private add a new Button and remove it and then try.

Upvotes: 0

rt2800
rt2800

Reputation: 3045

does your ASPX file has declaration of page directive having "CodeFile/Inherits" attribute? e.g. <@Page CodeFile="XYZ.aspx.vb" Inherits="XYZ" >

Upvotes: 2

Related Questions