Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

Convert Type Error Message

This is related to question 22884273

Receiving error Cannot convert type 'System.Web.UI.Control' to 'PackageControl.UserControl2' on second line below.  The code below comes under Public Class ......
{protected System.Web.UI.WebControls.Label ........

             PackageControl.UserControl2 obj = new PackageControl.UserControl2();
-------->obj = (PackageControl.UserControl2) LoadControl("UserControl2.cs");
             obj  .psServerName = psServerID;



0
66chawger
Asked:
66chawger
  • 7
  • 4
1 Solution
 
66chawgerAuthor Commented:
up'd the Point Value
0
 
andrewjbCommented:
Wel... what's the definition of PackageControl.UserControl2? What does it derive from?
0
 
66chawgerAuthor Commented:
Sorry about that:
PackageControl.UserControl2 is derived from System.Windows.Forms.UserControl, so we do have apples to oranges because the code behind for which I am instatiating it is System.Web.UI.Control.
Do I need to cast?  if so how?

Also, other than instantiating UserControl2 in the code behind, could I register it at the top of the form and would this still allow me to access UserControl2's spServerName set() method in the code behind?
I am not sure about the syntax to register the control exactly..   Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
andrewjbCommented:
If they ain't got no common base class, you can't cast them to each other in any way, shape or form.


What are you _actually_ trying to do here? What's going on overall?
0
 
66chawgerAuthor Commented:
That is what I figured, I thought that I possibly would be able to cast.

Anyhow I have Form1.aspx and UserControl1.cs.  I am trying to call the psServerName set method of the UserControl1 from Form1.aspx code behind as indicated previously.  

            "PackageControl.UserControl2 obj = new PackageControl.UserControl2();
-------->obj = (PackageControl.UserControl2) LoadControl("UserControl2.cs");
             obj  .psServerName = psServerID;"

All I want to do is set the psServerName in UserControl1.cs to the psServerID from Form1.aspx code behind.  

I hope this explains it all.  Thanks again for your responses!

0
 
andrewjbCommented:
I'm a Forms guy, not asp, but...

If UserControl2 is a Windows.Forms control, then LoadControl("UserControl2.cs") isn't going to work....

I think you need to make your control a web control rather than a forms one, don't you?
0
 
66chawgerAuthor Commented:
Unfortunately, this is legacy code.  Attempting to change to a web form would require drastic changes to the entire project.  There has got to be a way to pass a variable.  This is what I have to work with.  :(
0
 
andrewjbCommented:
Forget the cast for a moment.

Does :

obj x = LoadControl("UserControl2.cs");

work at all? I suspect not! What's 'x' after this line gets executed?

0
 
66chawgerAuthor Commented:
andrewjb, sorry for not getting back to you sooner.  I had a higher priority item come in.  I will try the code above and let you know the results of 'x' after execution.  Thanks!!!!!!
0
 
66chawgerAuthor Commented:
I was able to resolve this by passing a param in the aspx when calling the user control and using the get and set method to value the URL.
0
 
66chawgerAuthor Commented:
Solution was to use Get and Set method in UserControl by passing parameter in aspx on the redirect to the usercontrol.
<OBJECT id=UserControl2 style="WIDTH: 850px; HEIGHT: 800px; overflow: scroll;" height=800  align=middle
data=data:application/x-oleobject;base64,IGkzJfkDzxGP0ACqAGhvEzwhRE9DVFlQRSBIVE1MIFBVQkxJQyAiLS8vVzNDLy9EVEQgSFRNTCA0LjAgVHJhbnNpdGlvbmFsLy9FTiI+DQo8SFRNTD48SEVBRD4NCjxNRVRBIGh0dHAtZXF1aXY9Q29udGVudC1UeXBlIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD13aW5kb3dzLTEyNTIiPg0KPE1FVEEgY29udGVudD0iTVNIVE1MIDYuMDAuMjkwMC4yNTIzIiBuYW1lPUdFTkVSQVRPUj48L0hFQUQ+DQo8Qk9EWT4NCjxQPiZuYnNwOzwvUD48L0JPRFk+PC9IVE1MPg0K 
align=bottom 
classid="http://<%=Request.ServerVariables["Server_Name"]%>/aspnet/safecoaccess/AccessSafecoControl.dll#AccessUserControl.UserControl2" VIEWASTEXT>
<param name="ServerName" value="<%Request.ServerVariables"Server_Name"]%" />

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now