I had some strange erros when adding a user control
First of all it told me:
Element 'searchresults' is not a known element. This can occur if there is a compilation error in the Web site
The I tried to compile the user control and it said
The name 'lnavigation' does not exist in the current context
So I figured the variable wiring up wasnt working and added a definition for lnavigation manually. The I got.
The type 'referencesearchresultsusercontrol' already contains a definition for 'lnavigation'
Very frustrating.
Later I also got
The file 'src' is not a valid here because it doesn't expose a type in the register tag.
Turns out that the problem was that the register tag was the problem and I had to remove the ".cs" from the src attribute.
Change
<%@ Register TagPrefix="blahblah" TagName="searchresults" Src="searchresults.ascx.cs" %>
To
<%@ Register TagPrefix="blahblah" TagName="searchresults" Src="searchresults.ascx" >
Tuesday, April 29, 2008
Monday, April 28, 2008
.Net Regular Expressions and accented / unicode characters
I was trying to replace any non letter characters using regular expressions which turned out to be a bit of a pain when unicode / accented characters were used.
I ended up trying to match the stuff that I wanted and remove everything else. Regular expressions aren't really set up like this as there isn't really a "not" operator.
This page was very useful:
http://www.regular-expressions.info/unicode.html
This expression did the trick for me, it matches everything, but only replaces (with the match) matches that I wanted.
Regex.Replace(authors, @"(?(?\p{L}\p{M}*|[ ,;|-])|(?.))", "${allowed}", RegexOptions.Compiled | RegexOptions.Multiline);
\p{L} matches any letter character without a separate accent
\p{M} matches any accent
\P{L}\p{M}* matches any letter character with any number of accents (it is possible to have more than one)
[ ,;|-] matches any special characters that I wanted to keep
the all group matches everything
the allowed group matches characters that I want to keep
the not allowed group matches anything else
The first expression in an or (|) group is the one that is matched so is the allowed group matches then the not allowed doesn't.
"${allowed}" in the replace string replaces a match with the contents of the allowed group. Since everything is matched nothing remains of the original string. If an not allowed match is replaced there is nothing in the allowed group.
Some notes:
Accented characters in unicode can be represented by a single character (for legacy reasons) or as a combination of a base character and one or more accent characters.
Thus a single character on screen such as é can be represented by either one or two unicode characters.
It is thus not possible to match accented characters in the usual way using square brackets [].
I ended up trying to match the stuff that I wanted and remove everything else. Regular expressions aren't really set up like this as there isn't really a "not" operator.
This page was very useful:
http://www.regular-expressions.info/unicode.html
This expression did the trick for me, it matches everything, but only replaces (with the match) matches that I wanted.
Regex.Replace(authors, @"(?
\p{L} matches any letter character without a separate accent
\p{M} matches any accent
\P{L}\p{M}* matches any letter character with any number of accents (it is possible to have more than one)
[ ,;|-] matches any special characters that I wanted to keep
the all group matches everything
the allowed group matches characters that I want to keep
the not allowed group matches anything else
The first expression in an or (|) group is the one that is matched so is the allowed group matches then the not allowed doesn't.
"${allowed}" in the replace string replaces a match with the contents of the allowed group. Since everything is matched nothing remains of the original string. If an not allowed match is replaced there is nothing in the allowed group.
Some notes:
Accented characters in unicode can be represented by a single character (for legacy reasons) or as a combination of a base character and one or more accent characters.
Thus a single character on screen such as é can be represented by either one or two unicode characters.
It is thus not possible to match accented characters in the usual way using square brackets [].
Tuesday, February 12, 2008
PageSetupDlg Misreporting Margins Problem
I was having trouble in Delphi because the TPageSetupDialog component was repoting the margins at o.5 inches but when the dialog was shown the margins were all shown as 1 inch. If the cancel button is pressed the margins are still reported as 0.5 inches. If the OK button is pressed the margins are now reported at 1 inch and the control and the screen now match up.
This is obviously confusing for a user. The program reads 0.5 inch margins from the dialog and uses these values. The user looks at the dialog and sees 1 inch margins and thinks everything is OK. The the printout shows 0.5 inch margins and the user starts to attack the computer.
The problem is that the pagesetupdlg defaults to 1 inch margins instead of using the values in the rtMargin parameter of the PAGESETUPDLG Structure (which is the Rect object the Delphi maps to its TPageSetupDialog properties).
To solve this set the psoMargins flag and the dialog will use the values in rtMargin instead of its silly defaults.
This is obviously confusing for a user. The program reads 0.5 inch margins from the dialog and uses these values. The user looks at the dialog and sees 1 inch margins and thinks everything is OK. The the printout shows 0.5 inch margins and the user starts to attack the computer.
The problem is that the pagesetupdlg defaults to 1 inch margins instead of using the values in the rtMargin parameter of the PAGESETUPDLG Structure (which is the Rect object the Delphi maps to its TPageSetupDialog properties).
To solve this set the psoMargins flag and the dialog will use the values in rtMargin instead of its silly defaults.
Thursday, February 7, 2008
ASP.NET custom controls dll issues
I have an ASP.NET vb website that uses a large number of custom controls that I modify a lot during development. These rely a bit on some generic code from the application and some of the settings in web.config. Thus they are a bit of a pain to compile by themselves (as far as I know anyway).
I have since included customcontrols.vb into my project as well as the customcontrols.dll. Any change to customcontrols.vb has an effect as soon as the project is compiled but the dll is not changed.
So you'd think that the dll isn't required right? Its not being modified and the changes are present in the website. Right? Wrong, for some reason the dll still has to be there.
This is mainly just a note to myself not to delete it again and spend an hour trying to work out why the website wouldn't compile. I think the dll is required for asp to know about the declarative syntax for the controls, so it can't just be any dll. Then when the controls are actually created the customcontrols.vb code must take precedence over the dll.
I have since included customcontrols.vb into my project as well as the customcontrols.dll. Any change to customcontrols.vb has an effect as soon as the project is compiled but the dll is not changed.
So you'd think that the dll isn't required right? Its not being modified and the changes are present in the website. Right? Wrong, for some reason the dll still has to be there.
This is mainly just a note to myself not to delete it again and spend an hour trying to work out why the website wouldn't compile. I think the dll is required for asp to know about the declarative syntax for the controls, so it can't just be any dll. Then when the controls are actually created the customcontrols.vb code must take precedence over the dll.
Subscribe to:
Posts (Atom)