Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2010, 10:58 AM
Authorized User
 
Join Date: Mar 2009
Posts: 64
Thanks: 0
Thanked 1 Time in 1 Post
Default Inheriting from an ASP.NET control

Imar,

I am trying to extend the material from Chapter 8 to my application.

I want to have an asp:FileUpload control for use within an asp:UpdatePanel. The button on FileUpload does not have an AutoPostBack attribute. One of the recommended ways I have found from a Google search is to include another button to actually upload the file.

What I have tried to do is derive from asp:FileUpload thusly:

I started a new control, as you did in Chapter 8. In the .cs file I have

public partial class Controls_FileUpload_trk : FileUpload, IPostBackEventHandler

in the ascx file I have only a single line

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Controls_FileUpload_trk.ascx.cs" Inherits="Controls_FileUpload_trk" %>

In the aspx file where I want to situate the control I have

<%@ Register Src="~/Controls/Controls_FileUpload_trk.ascx" TagName="Controls_FileUpload_trk" TagPrefix="trk" %>

I cannot place the control, and when it is compiled I get the error

error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

Any help would be appreciated and / or a direction to a source that would help me solve this.

Thanks.
 
Old July 18th, 2010, 10:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can't inherit from a Server Control using a User Control file. Instead, you should inherit from the Server Control directly. In order to do that, create a new .cs class file in App_Code (or anywhere in the site if you're using a Web Application Project) and add a class inheriting from the Server Control to that file.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use asp.net we user control on asp 3.0 web i_shahid Java Basics 2 January 8th, 2008 09:04 AM
using asp.net web user control in asp 3.0 App i_shahid Classic ASP Professional 0 January 8th, 2008 07:32 AM
dynamic control (c# ASP.net) Hemang ASP.NET 1.0 and 1.1 Basics 0 June 28th, 2007 08:34 AM
Control in ASP.NET Manisha0605 .NET Framework 2.0 1 March 29th, 2007 02:33 PM
how to Use an Ocx Control in Asp.Net Sureshsnair General .NET 1 January 7th, 2005 03:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.