2

I'm trying to construct a custom control for ASP.NET I started by creating a Web Application in VS2010 and creating a new .ascx page. The page is called "TestBox" and it's just a single TextBox control with "This is a test" as the text.

I built the project and then included the DLL in another website in order to make sure I would be able to move controls. Based on a tutorial I found here I added the following line of code to the top of the page:

<%@ Register TagPrefix="TestControl" Namespace="TestControl" Assembly="TestControl" %>

Then I added this to the page itself:

<TestControl:TestBox ID="TestBox1" runat="server" />

The code compiles and the page loads without throwing up any errors, but when it loads it's completely blank. By introducing a deliberate runtime error, I determined that the TextBox is definitely being loaded, but the control itself still isn't showing up.

Am I missing something?

Code for the TestControl:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestBox.ascx.cs" Inherits="TestControl.TestBox" %>
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged">This is a test</asp:TextBox>

I haven't touched the Designer code or the .cs code in any way.

EDIT: Figured it out. I had declared a namespace for the .CS file but not the .ASPX file itself.

3
  • 1
    Have you looked at the rendered HTML to see if there are any clues there? Commented Jun 7, 2012 at 19:33
  • Just looked at it and no, there isn't any evidence of the box existing. Actually, there's this bit: '<div class="aspNetHidden">' '<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2NjE1NDk5MTdkZF/UiwtbRgDGFaWAQFsLslFDQfYySq5YfjtmszuryTmx" />' '</div>' Commented Jun 7, 2012 at 19:39
  • That's normal, that's the viewstate for the page. Can you post the code for your TestControl? Commented Jun 7, 2012 at 19:41

1 Answer 1

1

The answer was that I had to add a namespace to the ASPX file itself and not just the underlying code file. I forgot to add Class="TestControl.TestBox" to the page declaration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.