473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Using C# Interfaces and User Controls

Hi everyone

I am trying to create a .net web application, and I am having trouble
with an aspect of using user controls...

I want to be able to create a generic method of calling a number of
user controls, based on a variable that is passed to a parent form..
the folling is an excerpt of my code

ReportName = Request.QueryString["name"];
ReportPath = ReportName+".ascx";
Cert.Forms.InterfaceReport CReport;

CReport = (Cert.Forms.InterfaceReport) LoadControl(ReportPath);
CReport.LoadRequestData(Request);
divContainer.Controls.Add(CReport);
where the report class name is passed to the form in the Request
object, and is retrieved using the QueryString method. i then pass
some other Request information to the user control class instance that
is opened. doing some testing has revealed that the 2nd line of code
is working correctly. the problem comes however, when i try to add
the user control to a panel (called divContainer) on the parent form.
the error i am getting is shown below..

Argument '1': cannot convert from 'Cert.Forms.InterfaceReport' to
'System.Web.UI.Control'

If anyone has any ideas, they would be greatly appreciated....

Oct 25 '07 #1
6 9059
cs****@ballsolutions.com.au wrote:
[...]
divContainer.Controls.Add(CReport);

[...] the problem comes however, when i try to add
the user control to a panel (called divContainer) on the parent form.
the error i am getting is shown below..

Argument '1': cannot convert from 'Cert.Forms.InterfaceReport' to
'System.Web.UI.Control'

If anyone has any ideas, they would be greatly appreciated....
It seems to me that the error is fairly clear: you have something that
is a Cert.Forms.InterfaceReport, and you are trying to pass that to a
method that takes a System.Web.UI.Control.

I don't know anything about the Cert.Forms.InterfaceReport type (looks
like some custom type in your own namespace), but unless it inherits
System.Web.UI.Control somehow, your code just can't work.

If you want to create a control on the fly and add it to divContainer,
your control class will need to inherit System.Web.UI.Control.

Pete
Oct 26 '07 #2
On Oct 26, 10:23 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:
csm...@ballsolutions.com.au wrote:
[...]
divContainer.Controls.Add(CReport);
[...] the problem comes however, when i try to add
the user control to a panel (called divContainer) on the parent form.
the error i am getting is shown below..
Argument '1': cannot convert from 'Cert.Forms.InterfaceReport' to
'System.Web.UI.Control'
If anyone has any ideas, they would be greatly appreciated....

It seems to me that the error is fairly clear: you have something that
is a Cert.Forms.InterfaceReport, and you are trying to pass that to a
method that takes a System.Web.UI.Control.

I don't know anything about the Cert.Forms.InterfaceReport type (looks
like some custom type in your own namespace), but unless it inherits
System.Web.UI.Control somehow, your code just can't work.

If you want to create a control on the fly and add it to divContainer,
your control class will need to inherit System.Web.UI.Control.

te problem is that i am unable to inherit the control class in my
interface, because that is not allowed by vis. studio...

Oct 26 '07 #3
cs****@ballsolutions.com.au wrote:
te problem is that i am unable to inherit the control class in my
interface, because that is not allowed by vis. studio...
You haven't posted enough code for us to understand why that is the
case. I think it's possible you're mistaken about that. But if it's
true, then you simply cannot do what you want.

It doesn't really matter _why_ your class doesn't inherit the necessary
class; if it doesn't, you can't use an instance of that class as a
parameter to the ControlCollection.Add() method.

Pete
Oct 26 '07 #4
Liz

what is this CReport type? something like a Crystal Report type? perhaps
you have to add a container which inherits from System.Web.UI.Controls
first, and THEN add your report type to THAT container ... just a guess;
there's not enough information here to provide an answer
<cs****@ballsolutions.com.auwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
On Oct 26, 10:23 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:
>csm...@ballsolutions.com.au wrote:
[...]
divContainer.Controls.Add(CReport);
[...] the problem comes however, when i try to add
the user control to a panel (called divContainer) on the parent form.
the error i am getting is shown below..
Argument '1': cannot convert from 'Cert.Forms.InterfaceReport' to
'System.Web.UI.Control'
If anyone has any ideas, they would be greatly appreciated....

It seems to me that the error is fairly clear: you have something that
is a Cert.Forms.InterfaceReport, and you are trying to pass that to a
method that takes a System.Web.UI.Control.

I don't know anything about the Cert.Forms.InterfaceReport type (looks
like some custom type in your own namespace), but unless it inherits
System.Web.UI.Control somehow, your code just can't work.

If you want to create a control on the fly and add it to divContainer,
your control class will need to inherit System.Web.UI.Control.


te problem is that i am unable to inherit the control class in my
interface, because that is not allowed by vis. studio...

Oct 26 '07 #5
cs****@ballsolutions.com.au wrote:
te problem is that i am unable to inherit the control class in my
interface, because that is not allowed by vis. studio...
By the way, a couple of examples of how to work around the lack of
inheritance in an interface:

* Use an abstract class instead. An abstract class can inherit
some other class, providing you the inheritance required to make your
code work.

* Define a "ToClass()" method or "Class" property in the interface.
Implementors would be required to implement the necessary behavior to
convert the interface instance to something appropriate (for example,
simply cast the interface implementor instance to the necessary class).
You wouldn't get compile-time type safety though.

Finally, if for some reason you don't really want the interface to
require the implementor to inherit from the necessary class
(Web.UI.Control in this case), but you believe that at that point in
code you have good reason to believe that the implementor does in fact
inherit from the necessary class, you can simply cast the interface
reference to the necessary class. As long as the instance actually is
of the appropriate type, it should work.

Pete
Oct 26 '07 #6

<cs****@ballsolutions.com.auwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
On Oct 26, 10:23 am, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com>
wrote:
>csm...@ballsolutions.com.au wrote:
[...]
divContainer.Controls.Add(CReport);
[...] the problem comes however, when i try to add
the user control to a panel (called divContainer) on the parent form.
the error i am getting is shown below..
Argument '1': cannot convert from 'Cert.Forms.InterfaceReport' to
'System.Web.UI.Control'
If anyone has any ideas, they would be greatly appreciated....

It seems to me that the error is fairly clear: you have something that
is a Cert.Forms.InterfaceReport, and you are trying to pass that to a
method that takes a System.Web.UI.Control.

I don't know anything about the Cert.Forms.InterfaceReport type (looks
like some custom type in your own namespace), but unless it inherits
System.Web.UI.Control somehow, your code just can't work.

If you want to create a control on the fly and add it to divContainer,
your control class will need to inherit System.Web.UI.Control.


te problem is that i am unable to inherit the control class in my
interface, because that is not allowed by vis. studio...
It's not allowed by .Net System.Web.UI.Control not VS.

It looks like you need a Base Page that has System.Web.UI.Control and this
Cert.Forms thing defined as Interfaces.

You derive your Web page off of the Base page so that both Interfaces can be
used.

I don't know if you can just have your aspx Code Behind file to just have
two interfaces without using a Base Page. You can try it.

public partial class SomeClass : System.Web.UI.Control,
Cert.Forms.InterfaceReport

You also may need to post msnews.microsoft.com newsgroup for ASP.Net or .Net
Webforms.

Oct 26 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Franco Gustavo | last post by:
Hi, Please help me to understand this, because I don't see what I'm missing. I was reading a lot of examples on Internet that explain that C# doesn't implement multiple inheritance it...
4
by: Michael | last post by:
Hi, I would like to design my application with several different user interfaces. I was thinking to create business objects with properties to retrieve/set values and display them either in...
11
by: Paul Tremblay | last post by:
Hi, I can't seem to locate the visual C++ (pre .NET) ng. This may be slight off topic here - please point me to the correct ng if it is. Without going into much detail (and repeating myself...
3
by: EJ1003 | last post by:
Hello I would like to create Activex Control uisng C# and use it in ASP.Net webform. User Control is not solving my requirement so I am going for Activex Control. Please guide me on this, how...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.