asp.net access user control in vb class - asp.net

i have a usercontrol named filebox (which wraps a fileupload and some related stuff)
in a certain .net class i have need to use this type as a ctype
but i cant seem to call ctype(aobject,filebox)
or either ctype(aobject,Controls_filebox) (which is the correct name)
how can i convert an object to this type?
thanks a million!

You need to add the class' namespace.
It's probably in the ASP namespace; you can check in the Object Browser.
You can change the namespace by adding Class="My.Namespace.Filebox" in the <%# Control directive.

Related

Google Maps Control for ASP.NET

I tried to use this Google Maps Control, but I keep getting this error:
The base class includes the field 'GoogleMapForASPNet1', but its type
(Vehicle_Tracking_System.GoogleMapForASPNet) is not compatible with the type of control
(ASP.googlemapforaspnet_ascx).
Note that the control is codefile.
You may check that :
its containing page is also codefile (or change the control's source to codebehind)
if you plan to use it in the .aspx.cs, you use the directive <#reference control="..."
if your .aspx.cs is a partial class, the control should be declared automatically
Hope this will help,
Note : Make sure that the version of the System.Web.Extension library is the same as what you have selected when you added the reference.
Example you are adding "System.Web.Extensions, Version=4.0.0.0"
and the reference has "System.Web.Extensions, Version=1.0.61025.0".
This is a better user control,
http://shabdar.org/asp-net/70-google-maps-control-for-aspnet-part-1.html

ASP.NET CodeFileBaseClass attribute vs. inherit from System.Web.UI.Page

I've just created a base class for my pages by inheriting from System.Web.UI.Page:
public abstract class PageBase : System.Web.UI.Page
{
...
}
When I noticed that you can also declare a base page in an ASP.NET view:
<%# Page Language="C#" CodeFileBaseClass="PageBase.cs" CodeFile="page.aspx.cs"
Inherits="page" %>
Can someone explain what the pros and cons of either method are? When would you use one over the other, or are they both the same? What happens if you used both at the same time?
CodeFileBaseClass, CodeFile, Inherits work together with inheritance, not in place of inheritance.
For example, specifying CodeFile="page.aspx.cs" without page.aspx.cs existing will result in:
Parser Error Message: The file '/page.aspx.cs' does not exist.
Assuming page.aspx.cs exists, specifying CodeFileBaseClass="PageBase.cs" without PageBase.cs existing will result in:
Parser Error Message: Could not load type 'PageBase.cs'.
On the other hand you may inherit from PageBase without specifying the CodeFileBaseClass attribute. This however could result in possible unexpected behaviour when referencing controls on the page from the base class.
To quote from Microsoft's #Page MSDN Documentation:
CodeFileBaseClass
Specifies the type name of a base class for a page and its associated code-behind class. This attribute is optional, but when it is used the
CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario, where you define common
fields (and optionally, associated events) in a base class to
reference the controls declared in a Web page. Because of the ASP.NET
code generation model, if you defined the fields in a base class
without using this attribute, at compile time new member definitions
would be generated for the controls declared in the Web page (within a
separate partial class stub), and your desired scenario would not
work. But if you use the CodeFileBaseClass attribute to associate
the base class with the page, and you make your partial class (its
name is assigned to the Inherits attribute and its source file is
referenced by the CodeFile attribute) inherit from the base class,
then the fields in the base class will be able to reference the
controls on the page after code generation.

ASP.NET - ascx.designer 'properties' not showing up in reflection at runtime

I have a very simple setup, single mycontrol.ascx with assoicated mycontrol.ascx.designer.vb and mycontrol.ascx.vb file.
mycontrol.ascx embeds a single reference to a custom control: "MyMenu":
<mM:myMenu id="myMenu1" runat="server" />
This has created a protected reference in the mycontrol.ascx.designer.vb file:
Protected WithEvents myMenu1 As Global.CustomControls.MyMenu
Now, when I breakpoint the Page_Load() event of mycontrol.ascx, and inspect the members returned from the type via:
Me.GetType().GetMembers()
I cannot any reference to myMenu1. If I look at the control with intellisence, the property is accessible:
Me.myMenu1
Can anyone explain exactly what I'm missing and what I need to do to access designer created properties at runtime through reflection?
Cheers
Yum.
Your .acsx file creates a separate class (generated by the compiler) that inherits the codebehind class.
GetMembers only returns the members defined directly on the class, not any members inherited from its base class.
You need to get the members defined on the base class, like this:
Me.GetType().BaseType.GetMembers()
what I need to do to access designer created properties at runtime through reflection?
I don't know your menu control but you don't need to grasp the members of the user control, you need to get to the members of the menu control.
myMenu1.GetType().GetMembers()
Besides why use reflection? Doesn't your custom control expose properties with which you can set your settings like
myMenu1.SelectedMenuItem = 3

asp.net: Inheriting from controls that use embedded resources and me.GetType()

I'm having some trouble trying to inherit a control that uses an embedded resource.
the trouble is - this control uses me.GetType() instead of GetType(ControlName).
now when I try to use the derived control, it looks for the resources in the derived control's assembly, instead of the base control assembly, and obviously - doesn't find them.
how can I fix this?
Since the call is in the base control's definition, there isn't much you can do if you can't override the method where its called; you could duplicate the resource file if possible, or try to override that method where the resource is being called. It's hard when you don't have control over the base class.
It's also hard to advise when I don't know what the code looks like; if you could post the signature of the part of the class in question and refer to this in your question, that would help.
HTH.

"using" namespace equivalent in ASP.NET markup

When I'm working with DataBound controls in ASP.NET 2.0 such as a Repeater, I know the fastest way to retrieve a property of a bound object (instead of using Reflection with the Eval() function) is to cast the DataItem object to the type it is and then use that object natively, like the following:
<%#((MyType)Container.DataItem).PropertyOfMyType%>
The problem is, if this type is in a namespace (which is the case 99.99% of the time) then this single statement because a lot longer due to the fact that the ASP page has no concept of class scope so all of my types need to be fully qualified.
<%#((RootNamespace.SubNamespace1.SubNamspace2.SubNamespace3.MyType)Container.DataItem).PropertyOfMyType%>
Is there any kind of using directive or some equivalent I could place somewhere in an ASP.NET page so I don't need to use the full namespace every time?
I believe you can add something like:
<%# Import Namespace="RootNamespace.SubNamespace1" %>
At the top of the page.
What you're looking for is the #Import page directive.

Resources