RichardTheKiwi RichardTheKiwi - 4 months ago 46
ASP.NET (C#) Question

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
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.


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>


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