Archive for Tips and Tricks

Tips/Tricks - How to control MaxLength of Multiline TextBox in ASP.NET 1.1?

Problem : The users can enter as much charaters as he wants in Multiline Textbox even MaxLength of this textbox is set to a particular value. Obviously, this is a bug of ASP.NET.

Details of problem : When the TextMode property of textbox is set to Multiline, the MaxLength property wont be handled in controlling the maximum length of users inputs.

maxlength-of-textbox-1.jpg

Demo Download

Steps to reproduce this issue (for those who doesn’t know that problem)

  1. Download Sample file
  2. Set “Problem.aspx” page as a startup page (There are two textboxes in this page. One is Multiline textbox (TextBox1.TextMode = Multiline) and another textbox is singleline textbox (TextBox2.TextMode = SingleLine). The MaxLength of Both textboxes are 10. )
  3. Run the project
  4. Type something more than 10 characters in both textboxes
    Observe: You can type as many characters as you wants in TextBox1 (1st Textbox) but not in Textbox2 (2nd Textbox)

Solution ~

This problem can be solved by using Javascript to track how many characters typed in textbox. If the length of characters are over limited number (max number) then we can simply ignore what the user type by returning “false” in javascript function.

Step #1. Put the following function in your page.


<script language="javascript">
function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))return false;
}catch(e){
}
}
</script>

Step #2. Put the JS function in onkeypress event of Textbox.


&lt;asp:textbox id="TextBox1" runat="server" Width="232px" TextMode="MultiLine" Height="48px" style="Z-INDEX: 104; LEFT: 136px; TOP: 336px"
onkeypress=<strong>"return textboxMultilineMaxNumber(this,10)"</strong>></asp:textbox>

Run the sample

  1. Set “Solution.aspx” as startpage in the demo project that you just download.
  2. Run the project
  3. Type something more than 10 characters
    Observe: Both textboxes won’t let you type if the characters that you type are more than 10 as its defined.

Listen to any PDF file instead of reading

I think that it might be a old news for you all. But it’s pretty new to me. I used to read a lot of eBooks but I didn’t know that there is a feature like that in Adobe® Reader®. I just come to know that we can listen to any PDF file instead of reading with Adobe Reader. 

Shortcuts~

Ctrl+shift+b - to hear the entire Document
Ctrl+shift+v - to hear the page
Ctrl+shift+c - to resume
Ctrl+shift+e - to stop

Open any PDF file and play with those shortcuts above.

You may read the details in the following links.

  1. Hello TTS(Text-to-Speech technology): Listen to your PDF
  2. Listen to Your PDFs (Adobe - Design Center)

Thanks to Rahul for fowarding this mail.

AssemblyVersion - BuildNo Limitation

I was trying to compile a new build of our project today morning. We used to give the build no of our project’s assembly in YYMMDD format. (Build No “70112″ for 12th January,2007). So, I changed the version no of assembly to “2.2.70112.2″ [<major version>.<minor version>.<build number>.<revision>] (More Info) before compiling the project.

When I tried to compile, I got the following error.

Error emitting ‘System.Reflection.AssemblyVersionAttribute’ attribute — ‘The version specified ‘2.2.70112.2′ is invalid’

I was so surprised about it. I thought, we can give any number as we like for the version of our assemblies. Then, I googled it and I came to know that there are a lot of people who are facing the same problem. and I also found the reason why this error occur and how we should fix this problem.

Why this problem?

This article said,

Binary version number for the file. The version consists of two 32-bit integers, defined by four 16-bit integers. For example, “FILEVERSION 3,10,0,61″ is translated into two doublewords: 0×0003000a and 0×0000003d, in that order. Therefore, if version is defined by the DWORD values dw1 and dw2, they need to appear in the FILEVERSION statement as follows: HIWORD(dw1), LOWORD(dw1), HIWORD(dw2), LOWORD(dw2).

Solution

This article “Fixing invalid version number problems with the AssemblyInfoTask” said,

The arrival of 2007 bought a flurry of e-mails to the MSBuild team from people having trouble with the AssemblyInfoTask. The symptom is simple to describe - the builds start to fail with the following error:

Error emitting ‘System.Reflection.AssemblyVersionAttribute’ attribute — ‘The version specified ‘1.0.70102.1′ is invalid

The fix to get builds going again is to change the date format used to generate the build number to something other than the default “yyMMdd”. The date formats are in Microsoft.VersionNumber.target, located in %program files%\MSBuild\Microsoft\AssemblyInfoTask, and there are two of them (one for file version and one for assembly version). You can use any format you want. Within Visual Studio we’re now using 01MMdd.

Note that you may have to go in and hand-edit your assemblyinfo.* files to change their version number back to a default starting point of 1.0.0.0 to get your builds going again.

However, I don’t think it’s a solution since we are not able to use the way that we already used to it.
So, Be careful when you are assigning the version of your build. “[assembly: AssemblyVersion("65534.65534.65534.65534")]” is maximum.

References ~
AssemblyFileVersions: 2.0.0.071005 is bad, but 2.0.0.061005 is good
Why are build numbers limited to 65535?
Fixing invalid version number problems with the AssemblyInfoTask

5 HTML elements you probably never use (but perhaps should)

Ya. I have been working on the web development since I was in Collage. But there are a lot of tags that I never used in my project.

Here is one article that I found in internet. You will see the following tags which are (probably) never used in our web applications that we developed. Chect it out and hopefully, it will be useful for some cases.

  • <address>
  • <q>
  • <optgroup>
  • <acronym> or <abbr> combined with the title attribute
  • <fieldset> and <legend>

Link: 5 HTML elements you probably never use (but perhaps should)

Tips : devenv.exe Problem

Since I am super busy in my work :P, running devenv.exe from Run menu instead of finding the shortcut of VS 2003 in Start Menu can save me a lot of time. When Microsoft distributed a hundred versions of Whidbey I gladly installed/uninstalled the latest version for checking its new features [along with sending a thousand error report to microsoft .. ]:-))… Unfortunately, after UNINSTALLING Whidbey from my machine I was unable to call “devenv.exe” to launch Visual Studio 2003 coz some of register keys have been changed when I installed Whidbey.So after a lot of effort I found out how to fix this and I am sharing it with you all

Steps to perform ~
1) Open registry editor (regedit.exe)
2) Go to this path
HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\
Windows\CurrentVersion\App Paths\devenv.exe”

3) Check the value of this key.. [ you will see this string "
C:\Program Files\Microsoft Visual Studio 8\
Common7\IDE\devenv.exe"]

4) Change this string to
“C:\Program Files\Microsoft Visual Studio .NET 2003\
Common7\IDE\devenv.exe”5)

Done!!

Check : Type “devenv” in run menu… Wow! Visual Studio 2003 is opening…
Hope you will find it useful..

VS.NET Add-In - Create Property Macro

If you are using this macro, the required property will be automatically created as soon as you declare the private variable in your code.

More: Create Property Macro for VS.NET

Thanks to Fons Sonnemans.

Note: This post is moved from my old blog.