Google Maps Control for ASP.NET - 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

Related

Using the ASP.NET ClientServerManager method or property to get name of control

Does the ASP.NET ClientServerManager provide some method or property to return the name of an ASP.NET control in the generated html page that could be used to write the javascript (using RegisterClientScriptBlock) in the code-behind? The actual generated control names can be quite long and unknown (I am also using master pages). I would like a generic way to write the javascript text and have the actual names of the controls be added to the javascript string. I would expect some method that I pass in the name of the control and it returns the actual html control name. I have searched in the documentation of the ClientServerManager and could not find anything.
Control.ClientID is rendered as html tag ID, so you can use that property.
If you are worried about control names, check out ClientIdMode where you can specify this and make it much simpler.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx
Would this help your issue?

asp.net access user control in vb class

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.

How to Consume a Custom Server Control

I seem to be having a lot of trouble with this.
I want to create an ASP.NET control that implements some core logic, and then I want to be able to derive several controls from that, which each implement their own specialized logic.
I started with a User Control, but I couldn't find a way to derive from it. I tried setting the Inherits attribute in the derived control but, no matter what I did, the derived control just didn't seem able to recognize the base control.
So then I tried a custom server side control by using a regular class that inherits from Control. (Note that all my rendering is done from code.) But I can't seem to find any way to get a page to recognize the control. I've tried different syntax in the #Register directive but either it tells me the src attribute is missing or it just can't find the control. (Note that I prefer not to create a separate assembly if I don't have to.) I have no idea what to put as the assembly if the control is from the current assembly.
Can anyone make suggestions on this? Any examples that would work for my configuration, or perhaps a different approach entirely?
Note that I am not currently using page/control code-behind. All my page scripting is stored in the same file as my markup.
In fact, despite various error messages about missing attributes in the #Register directive, I found it works just fine if I reduce the number of attributes in this directive to just tagprefix and namespace.

Use user control in the same folder as the page

I get this message at runtime of ASP.NET 2 page :
The page 'MyFolder/blabla.aspx' cannot use the user control 'MyFolder/MyControl.ascx', because it is registered in web.config and lives in the same directory as the page.
Of course I can separate them to 2 different folders and thus solve the problem, but the question is :
WTF !?!?! Why I can't put them in the same folder ?!
Why can't they all .. get along !?! :)
Thanks
This limitation is by design due to an internal design consideration re: performance.
See here for further info.
Remarks
The TagPrefixInfo class allows you to programmatically access and
modify tag-prefix information stored in a configuration file. It
provides the same functionality as the ASP.NET #Register
directive. Tag prefixes associate a "namespace" in ASP.NET to the
assemblies and namespaces that must be included for custom controls
and user controls to work properly. TagPrefixInfo objects are stored
as members of a TagPrefixCollection object. The
TagPrefixCollection class allows you to programmatically access
and modify the controls subsection of the pages section of a
configuration file.
TagPrefixInfo objects are added to the collection using the add
element and specifying a value for the tagPrefix attribute along
with values for other relevant attributes. The other required
information varies based on the kind of control you will use with the
specified tag prefix:
If it is a user control, you must define the TagPrefix, TagName, and Source properties.
If it is a custom control, you must define the TagPrefix, Namespace, and Assembly properties. The Assembly
property is not required if the control is in the application code
directory. The same tagPrefix value can be used to map to multiple
assemblies or namespaces.
Note When a source is specified, the user control itself must not be in the same directory as the page. If it is, you get a run-time
error when you attempt to load the page.
If you register it in the page or user control instead of the web.config it will load properly.
Add the following to the top of the page.
<%# Register TagPrefix="MyControlTagPrefix" TagName="MyControlTagName" Src="~/MyFolder/MyControl.ascx" %>
I suspect you could do it without registering it, if it was essential.
You could probably have a PlaceHolder and then use .Controls.Add(LoadControl("path.ascx"))
But if it's not essential then put it in a different directory due to the reasons #Barry says.
The answer can be found inside the .NET Framework Reference Source code for System.Web.dll:
https://referencesource.microsoft.com/#System.Web/UI/TagNameToTypeMapper.cs,ced01a48dbbb9f9c
TryUserControlRegisterDirectives
Don't allow a config registered user control to be used by a page that lives in the same directory, to avoid circular references. More specifically, this would break batching because our simple dependency parser would not be able to detect the implicit dependency triggered by the presence of a tag (VSWhidbey 165042).

Getting namespace name not found for ASP.net user control

So I'm having problems when I try to publish the website.
I'm in visual studio 2008 sp1.
I've got a bunch of user controls and on a few pages I'm using them programatically.
I've got a reference on the aspx page
<%# Reference Control="~/UserControls/Foo.ascx" %>
Then on the code behing I use
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
If I navigate to the page it works fine, but when I goto publish the website I get a compile time error.
Argh, I'm bleeding development hours on this same issue. Does anyone have a solution to this ?
BTW: It builds if you uncheck "Allow this precompiled site to be updatable" (Right-click on the website, choose Property Pages, MSBuild Option)
But I need the site to be updatable.
I had this same problem - actually, in my case I could get it to compile and build my website, but it would blow up spectacularly when doing an automated build.
Try replacing your code as follows:
ASP.usercontrols_foo newFoo control = (ASP.usercontrols_foo)Page.LoadControl("~/UserControls/Foo.ascx");
with
USERCONTROLS_Foo newFoo control = (USERCONTROLS_Foo)Page.LoadControl("~/UserControls/Foo.ascx");
(Capitalization will be based on how you capitalized your directory name/control name - but in either case should highlight appropriately).
Specify a namespace for user control (see Dynamically Load a user control (ascx) in a asp.net website ).
I've found a solution for it. If i'll declare controls in user defined namespace, then I can use controls directly without using ASP or referencing it into aspx page.
It may have something to do with the specific type not being available. Can you change the control reference so the type and cast just use the base Control class:
Control control = Page.LoadControl("~/UserControls/Foo.ascx");
Yes, I can cast it to Control. But then I lose direct access to the methods on the usercontrol.
I know that I can access the methods by reflecting into the control, and I've successfully done that but that's far from ideal to access all the other user controls on the site.
Also, the follow-up error is that it cant find the usercontrols that on the markup
<%# Register src="CategoryRows.ascx" tagname="CategoryRows" tagprefix="abc" %>
<abc:CategoryRows ID="CategoryRows" runat="server" />
Note that I can run the site successfully both locally and on the server if I essentially XCopy the entire site (source code and all). But Publish fails.
Casting the user control may create many problem .my approach is to create a class (say control Class) put all the properties and method you need after casting and inherit this class from System.Web.UI.UserControl .Then in your user cotrol code file instead of System.Web.UI.UserControl user this control class .
now when ever you need casting cast with this class only . it will be light casting as well.
Please check:
Do you have any website.publishproj file?
If it exists, then delete and try again and publish code.

Resources