1

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.
John Saunders
  • 160,644
  • 26
  • 247
  • 397
RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262

1 Answers1

1

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
GregL
  • 37,147
  • 8
  • 62
  • 67
  • I can't see the .aspx.designer.vb file (discountasp.net FTP) which I am sure contains the Init and code wireup code. How do I add them manually in the .aspx.vb file? – RichardTheKiwi Mar 09 '12 at 02:29
  • @Richardakacyberkiwi I have added example designer code to my answer. Does that help you? – GregL Mar 09 '12 at 02:40
  • @Richardakacyberkiwi Also note that because the `@Page` directive has the `AutoEventWireup` property equal to `true`, you don't need to have code in your Init like in C# to "wire-up" the event handlers. Instead, the `Handles` keyword on the event handler will do that for you. – GregL Mar 09 '12 at 02:43
  • But there should still be a designer file? Would it exist on the web server or is it for vs dev only? – RichardTheKiwi Mar 09 '12 at 03:23
  • There does not need to be a designer file, no. It is purely a convenience/convention used when working with Visual Studio that purely contains the member variables for each control (in ASP.NET, for Winforms apps it also contains all the property-setting code like Height, Width, position, etc). You can put all this information in your own code-behind file if you wish, it's just not quite as neat. Just search for where the member variables for the other controls on the page are declared in your code, and add a similar line for the button in question. – GregL Mar 09 '12 at 03:33