ASP.NET VB Page_Load not firing - asp.net

Getting straight to the point, I've been searching around and can't find a solution to this. I have an ASP.NET web page with a VB code behind that isn't entering the Page_Load Sub.
I've read suggestions regarding adding "Handles Me.Load" to the Sub or checking the AutoEventWireup(tried setting it true, it's currently set to false).
I'm not finding anything so any help is appreciated in advance. Below is some of the code.
Front End:
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPage.Master" CodeBehind="ThisPage.aspx.vb" Inherits="Project.ThisPage" %>
<asp:Content ID="Content" ContentPlaceHolderID="ContentPH" runat="server">
<%-- insert content here --%>
</asp:Content>
Back End:
Partial Public Class ThisPage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Insert logic here
End Sub
End Class
I assume other code shouldn't be necessary as the only thing happening is some variables are being set and assigned to a control that's on the page. If that's not the case I can add more. I tried setting a break point and it's just never entering the sub.

If this is a partial class, the aspx page should inherits from the base class. Suppose the base class is Base1, then try change the .aspx file line
Inherits="Project.ThisPage"
to
Inherits="Base1"

This happened to me today. It turned out that a colleague committed an .aspx file that had a call to a code-behind function that didn't exist.
A broken commit in other words.
I pulled the code and it built without errors in VS2015 but when the broken page was due to load, the browser reported that it couldn't find it. A breakpoint in page_load wasn't hit. There was nothing to debug.
It took me a while to figure it out (which is how I found myself here), so I'm adding this answer in case someone else has the same problem.

I had just upgraded to Windows 8.1 from Windows 7 and Visual Studio selected the wrong project in the solution as the StartUp project. Selecting the correct project resolved the issue.

Related

TagLib.Sharp on a website (vb.net) (Type 'TagLib.File' is not defined)

(Coding for VB.NET)
I am working with the TagLib-Sharp. I really enjoy how it works.
Very simple and straight forward. Well, within VS, it is, anyway.
I took the files and placed them on my web server, of which included the BIN folder that VS created with the DLL files when I referenced the TagLib-Sharp.dll file.
When I run the site through my browser, I get the following error.
Type 'TagLib.File' is not defined
I was told that I had to create a Namespace for it, so I did that. I also included all the IMPORTS for the different taglib's and that did not work.
Here is the code that I am working with.
default.aspx
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="TagLib._Default" %>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
default.aspx.vb
Imports TagLib
Imports TagLib.IFD
Imports TagLib.IFD.Tags
Imports TagLib.Xmp
Imports TagLib.Id3v2
Namespace TagLib
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim mp3 As TagLib.File = TagLib.File.Create("G:\InetPub\wwwroot\Media\m.mp3")
Dim strAlbum As String = mp3.Tag.Album
Label1.Text = "Album: " + strAlbum
mp3.Dispose()
End Sub
End Class
End Namespace
I also registered the DLL file with my system.
%windir%\microsoft.net\framework\v2.0.50727\regasm G:\WebFiles\taglib-sharp.dll /codebase
I also read about this error, where it deals with the .NET version that was used for the file and what the project is made with.
I changed the version of .net down to 2.5 and then up to 3.5 and then back to 4.5 and it did not matter. Nothing seemed to work. (Other than a lot of errors when I went down to 2.5, it was a mess)
But nothing seems to be working. Any idea's on this would be wonderful. Reading the mp3 metadata is something that I have been wanting to add to an ongoing project for many years. And I am this close, but cannot seem to cross that finish line.
Thanks in advance for all assistance on this annoying issue.
CodingEE
OK, for anyone that runs into this issue.
This is how you fix it.
https://blogs.msdn.microsoft.com/tolong/2006/11/16/how-to-get-your-publickeytoken/
Works like a charm.
I am now viewing the site on a web server.
NICE!!!!!
CodingEE

* is not declared. It may be inaccessible due to its protection level

I've got a problem with one of my web forms pages.
this is how it started.
I needed to completely revamp a page, I renamed the old pages default.aspx.vb.old and default.aspx.old and created brand new default.aspx and default.aspx.vb pages
every time I add a control to the aspx page and try and reference it in the code behind, I get the error 'lblError' is not declared. It may be inaccessible due to its protection level
Page decalaration
<%# Page Title="" Language="VB" MasterPageFile="~/_Masters/Principle.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Magazine_Default" EnableViewState="false" %>
Label control in Default.aspx
<asp:Label ID="lblError" runat="server" CssClass="cError" Visible="false" />
Default.aspx.vb Code Behind
Partial Class Magazine_Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
lblError.Text = "There was a problem retrieving the magazines, please try again later"
End Sub
End Class
the page works, but visual studio will not build because it insists there is an error.
I thought it might be something up with my visual studio, like cache or something, so i nuked any temp files relating to the project.
and this morning a colleague did a git pull and has the same problem, errors are there, refuses to build but the page works.
The project itself is a website project, so there's no designer files where I can change the access modifier of the control.
I have also tried creating a new file, using the web form scaffolding that visual studio provides through add->web form, which has all the correct page directives in the .aspx and correct class declarations in the .aspx.vb, and it still does it.
There is also no red squiggly line under lblError.Text
When I create a new page in the different folder, it doesn't happen.
As you renamed old default.aspx page, you need to rename its class too. Generally when you rename aspx page, it will not rename class name automatically. So you need to do that manually.
So for default.aspx page,
Inherits="Magazine_Default_Old"
And for default.aspx.vb page,
Partial Class Magazine_Default_Old
This will solve issue.

Display loading gif while web page loads

I am using VS 2013 (asp.net, VB).
I have a web page that has a sub that executes a lot of code. The sub runs when the page loads but also when a button is clicked. The code within the sub basically imports values from a database and then saves them to an excel document which then performs a solver calculation and saves the excel document.
Anyway, the page load time is quite long so I want to display a loading GIF whilst the sub is executed.
I thought I could do something like the following.
The gif:
<div id="loadingGif" runat="server">
Loading. Please Wait....<br /><br />
<img src="images/RTO_Loader.GIF" alt=""/>
</div>
The page load:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
loadingGif.Visible = True
exportToExcelEvent()
loadingGif.Visible = False
End Sub
This doesn't work. I don't get any errors and the excel document saves fine. I haven't been able to find any understandable help on this. From what I have read threading may solve this but I cant seem to get it working.
Thanks if you can help.
Remove runat="server" attribute from 'loadingGif' div and replace it with:
style="display:none;"
Also remove lines from Page_Load that change visibility of that div.
Add OnClientClick event to button and set it to:
OnClientClick="document.getElementById('loadingGif').style.display = 'block';"
You can move that javascript to functiona and call function instead.
Another option is to use Ajax UpdatePanel with UpdateProgress.

aspx file not seeing code behind

I have a web application that I have been developing for some time. Yesterday when I loaded the project into VS the aspx files could no longer see the aspx.vb files. I reverted to the backup I had just made and everything was fine. Today, the same problem.
Example:
FILE: QuerySql.aspx
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master"
CodeBehind="QuerySql.aspx.vb" Inherits="WhatIsPouring_Ajax.QuerySql" %>
FILE: QuerySql.aspx.vb
Public Class QuerySql Inherits DBFunctions
Overloads Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
tbPassword.Text = sPassword
tbUser.Text = sUserName
tbServer.Text = sDBServer
End If
tbError.Text = "The system is loaded."
End Sub
There is a public variable sDBServer in the code behind file. The .vb file sees all the controls on the aspx side. If I type <%=sDBServer %> it displays an error "sDBServer is not declared..."
I believe it has something to do with the project configuration somewhere, but I don't know where to go the fix it. I have cleaned, built, rebuilt, etc many times.
Any help is appreciated.
Your code behind is missing the Partial keyword, e.g.
Partial Class QuerySql Inherits DBFunctions
Make sure that the designer generated class also has the same keyword to bind the ASPX file to your class.
If the designer file is missing you can regenerate it by right-clicking the ASPX page and selecting "Convert to Web Application"
How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
I have experience this problem as well. The vb.net web project i worked on, showed thousands of errors like 'BC30002 Type '....' is not defined. But this code did not seem to be faulty.
For me the following worked, but have no clue why!!:
Every designer class looked like this:
Partial Public Class CSSSRTOMOpleidersSearch
Removed the 'public' statement:
Partial Class CSSSRTOMOpleidersSearch
After that, the codebehind and designer were able to find each other

Add button to existing site

There is an existing site with no compiled DLLs, it's all .aspx.vb and .aspx files.
First question is that I can see
<%# Page Title="" Language="VB" MasterPageFile="~/MasterPage.master"
MaintainScrollPositionOnPostback="true" AutoEventWireup="true"
CodeFile="ThisPageName.aspx.vb" Inherits="ThisPageName" %>
But where is the file that it is inheriting from? I work in C# more and in the compiled variety, I can see this other source file
Partial Class ThisPageName
But where is the other half of the partial class to be found?
The reason for the question is that I'm trying to activate a commented out <asp:button> but when I add the event handler:
Protected Sub btnWasHidden_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnWasHidden.Click
I get this:
Compiler Error Message: BC30506: Handles clause requires a WithEvents variable
defined in the containing type or one of its base types.
And
E:\path\path\htdocs\ThisPageName.aspx.vb(304) : error BC30451:
Name 'btnWasHidden' is not declared.
I am not sure about non-compiled sites, but normally the "other half" of the page class is kept in the pagename.aspx.designer.vb file, which VS updates as you modify the markup (.aspx) page.
If you are doing this outside of the context of Visual Studio, you might need to add the member variable for the control to the class manually in either the designer file or your main class file (code behind).
EDIT: Here is how the .aspx.designer.vb file typically generates member variables for server-side controls:
Protected WithEvents <control_id> As <full namespace and type of control>
e.g.
Protected WithEvents TextBox1 As Global.System.Web.UI.WebControls.Button
Just follow that pattern in the normal code-behind .vb file and it should work.
In your case I believe it will be:
Protected WithEvents btnWasHidden As Global.System.Web.UI.WebControls.Button

Resources