Help Scanning Custom Web Controls

Hi,

I am using the Multi Language Plugin on my Asp .Net website. I have written a control that inherits from WebControl but the Text property is not getting added to the translation list when I scan my project.

The next property on the Web Control is shown below:

Localizable(true),
Bindable(true),
Category(%22Appearance%22),
DefaultValue(%22%22),
Description(%22The text to display within the hyperlink.%22)

public virtual string Text {
get {
object o = ViewState%22Text%22;
return ((o == null) ? String.Empty : (string)o);
}
set {
ViewState%22Text%22 = value;
}
}

How can I get the scan to detect all the Text properties for the control so I can select their contents for translation?

Thanks

Robin

To follow up on this, the control was not even being detected and was not showing up at all on the translation grid.

I solved this issue by moving the registering of the web control's assembly from the web.config to the aspx page itself. Although this isn't a clean solution (and something that could be added in the future as an enhancement perhaps), my custom web control now shows up on the translation grid.

However, the Text property ont he control is still not available to edit, even though I have marked it as localizable.

Thoughts?

Robin

Phil,

For a brief moment I got my web control's text property to show up ont he translation grid. I think it was because I removed the Bindable (true) attribute. However, on a re-scan the property then dissapeared again. So it is very close to working, just not quite.

Let me know if you want me to send you an further information to help you solve the issue, as I think it's a really useful tool that has saved me from hours of menial work thus far.

Thanks

Robin

Germany

Hi Robin,

I have just uploaded a new version (4.60.0017) which I think should fix this problem, and also handle controls which are registered via web.config.

I generated a new ASP.NET Server Control project in C# with VS 2008. It creates a control with a text property very similar to your definition. I then added the control to an ASP page and scanned it with the Add-In and it recognised the the Text property correctly.

You can download the new version with this link.

Phil


Germany

Hi Robin,

thanks for pointing these problems out.

The Add-In doesn't pick up on controls which are registered via the web.config file, as you have discovered. This shouldn't be too difficult to fix, so that it works as if they were registered in the aspx page.

That should then work for controls which are compiled into a different assembly, for example with
<%@ Register TagPrefix="ControlVendor" Assembly="ControlVendor" %>

The Add-In seems to have a general problem with web user controls defined within the same project, and registered with something like
<%@ Register TagPrefix="uc1" TagName="MyControl" Src="MyControl.ascx" %>

In the first case the Add-In reads the type information for the assembly. In the second case, there is no assembly name, and the Add-In fails to read the type information. The Add-In uses the type information to detect which properties are actually localizable. At present, I can't see a simple workaround. The quick and dirty solution would be to simply show all properties, including ones which may not be localizable. That's not really good, but probably better than not showing properties which are localizable, as at present.

I'm not yet sure why the text property is not editable. I will try to reproduce this in the next day or two.

Phil


Hi Phil,

I have downloaded and isntalled the new version of the plug in. Below is the behaviour I experienced:

All my custom User Controls that did not show up at all before now display on the controls grid. It seems that all their properties are listed, regardless of whether they have the Localizable attribute.

However, unfortuantely none of cusyom Web Controls show up any more on the controls grid. From the ouput window I can see the following messages when I scan an aspx page containing the web control:

Failed to load assembly FacebookNET.Web
Failed to get type FacebookHyperLink

So it looks like the assembly can't be loaded correctly. This wasn't happening before. I have tried registering the web control assembly on the page and in the web.config but both cause the same messages.

Robin

Germany

Ho Robin,

I will have to test this more.

The Add-In simply calls Assembly.Load with the text specified in the Register directive (or equivalent from web.config). It shows the same name in the error message, so in your case it has tried to load the assembly with
Assembly.Load ( "FacebookNET.Web" ).

Sometimes the assembly is a full name, like
"ORBWebControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=39f9d01eda9a0ee2"
but it doesn't have to be. For the web control that I made yesterday, the name was just "CS_WebControls", but Assembly.Load worked fine.

I will try to find out what could be going wrong in the next few days.

Phil

Phil,

Ok, thanks for the update. The assemby was definetly loading fine in the previous version so I'm sure it is related somehow. I put a test Assembly.Load statement in the code behind of the web page for the Assembly in question and it loaded fine with no errors. Don't know if that helps or not!

Robin

Germany

Hi Robin,

My impression is that loading the Assembly succeeds if the web control has already been loaded into a designer window, but fails otherwise!

When you add a reference to a Web Control, Visual Studio appears to copy the dll into the bin directory. I have now added an additional logic to try to load the assembly from the bin directory. If Assembly.Load(AssemblyName) fails, then I now try Assembly.LoadFile(ProjectDirectory\bin\AssemblyName.dll).

This is quite successful with my test project, but I admit it is just an ad hoc fix. There is probably a correct and reliable way to load the dll, and I doubt very much that this is it.

The new version is 4.60.0018. You can download it with this link.

Phil

Phil,

Thanks for updating it again so quickly. Unfortuantely it still doesn't load the assembly correctly, although it does get further than last time. Below is the output when I try and scan the html:

Exception System.IO.FileNotFoundException loading assembly FacebookNET.Web
Could not load file or assembly 'FacebookNET.Web' or one of its dependencies. The system cannot find the file specified.
Assembly file C:\.....\src\app\FacebookFootball.Web\bin\FacebookNET.Web.dll loaded
Exception System.Reflection.ReflectionTypeLoadException loading types from assembly FacebookNET.Web
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

I thinkthis problem is because Assembly.LoadFile does not load any dependencies, of which my Web Control has one. I think that if you change Assembly.LoadFile to Assembly.LoadFrom then it should work, as this loads all assembly dependencies too.

Thanks

Robin

Germany

Hi Robin,

I have changed Assembly.LoadFile to Assembly.LoadFrom in version 4.60.0019. Can you try it out?

Phil


Phil,

The change worked fine. The control now shows up fine and only the Text property displays in the grid. Thanks!

The only minor issue remaining is that all my User Control properties show up, regardless of whether they have the Localizable atribute. This is not a big deal as I can just choose to ignore them.

Thanks for being so swift to help. I shall reccomend your Add-In in the future

Robin