Wednesday, December 12, 2007

Visual Studio .Net Editor Tips - Part 1

1. Custom task list tokens:

So the task list is great because it provides you with information about build errors, annotations that you leave for yourself in your code, and by default there are some default tokens that you can leave for code annotations. There’s a to do token, so if you need to finish up a procedure or if you have a bug in your code, these are built in as part of Visual Studio.NET. But what you can actually do is create your own custom tokens for bugs, for notes that you want to leave to other developers on your team and so on, and you can leave these custom task list tokens, you can create them, by going to the tools menu, dropping down and selecting options, and then it’s within the tools options dialog box that you can create your own task list tokens.

2. Backward and forward navigation:

So in Internet Explorer you know we can go backward and forward from page to page, very easy to navigate that way, and we actually have a similar concept within the code editor in Visual Studio.NET so that if you want to navigate backward in your code our code editor actually keeps track of that and there’s a shortcut key that you can press to do this. If you want to navigate backward in your code you can go ahead and press control and then the hyphen key and that will navigate backward to the various places that you’ve been in your code.

3. Incremental Search:

This is kind of cool. Normally when you go ahead and press control F and you want to search for a particular string in your code you have to type in the entire string and then you can just search throughout your code to go ahead and find that. Incremental search is a little bit different, you press control and then the letter I and what that allows you to do is as you’re typing in the code editor will move around finding out each instance of the text that you’ve already typed. So that’s a slightly different pretty cool way to do searching.

4. Bookmarks:

Bookmarks is another way to leave little breadcrumbs in your code if you will. Bookmarks, you can set them very easily, anywhere that you want, let’s say if you’ve got code that you might be jumping back and forward to from time to time, you can leave a bookmark in your code by pressing control K control K and then you can navigate forward and backward within your bookmarks by pressing control K control N, that will move you to the next bookmark, or control K control P, and that will move you to the previous bookmark.

Very closely related to bookmarks are task list shortcuts. Essentially it’s the same concept, except in addition to seeing a little glyph in the margin of your code you actually also see an entry in your task list. So I can right click anywhere in my code and I select add task list shortcut, it’ll leave a little glyph in the margin of my code and it’ll create an entry in my task list.

5. Clipboard ring:

Clipboard ring, we may know this from using Office, any time you hit control C or you copy some text it adds it to the clipboard ring. And the clipboard ring stores I think up to 20 different code snippets or html markup, things like that. What’s cool in Visual Studio is that we store everything that you have in the clipboard up on the toolbox. Okay, there’s a tab called clipboard ring and you can see all those 20 code snippets that you may have control C’d or copied into the clipboard ring. Now if you want to get access to those and copy any of those into your code you can press control shift and then the letter V and that will go ahead and scroll through everything that you have in your clipboard so that you can find the right snippet and easily drop it into your code.

Source: MSDN blogs.

Monday, December 10, 2007

Javascript button click event - Firefox

In some instances we may need to perform a button click event through JavaScript.

This would be look like this:

<script language="javascript">
function doSomeThing();
{
//do something
var btn = document.getElementByID('btnHidden');
btn.click();
}
</script>


This will works fine in IE, but wont work in Firefox.
To get it work in Firefox add UseSubmitBehavior="false" property to button.

This will make the button postback with the ASP.NET postback model.
ex:-

<div style="display:none;">
<asp:Button id="btnHidden" runat="server"
OnClick="btnHidden_Click"
UseSubmitBehavior="false"
/>
</div>

How it works: Compare html generated by .Net framework with UseSubmitBehavior and without this.

With UseSubmitBehaviour="false" it will render onclick event for button & without this it wont render onclick event.

Scroll Event for DIV Tag - Licence Agreement Reading Confirmation

Technorati-

Hi Friends,

Recently we got a requirement from client that the user must read the "Licence Agreement", that doesn't mean to check the I Agree checkbox. The user must read the licence agreement. As we can't assure that the user will read the agreement. So the only way to know is to checking the scroll position of Licence Agreement box. If the scroll is reached to end of the box means that user has read the agreement.

Here is the sample program:

<div id="frAgreement" style="height: 170px; overflow: scroll;width:100% " onscroll="checkScrollPosition();">
Terms of Use<br/>
.
.
.
.
.
</div>
<input type="button" value="Submit" onclick="return isReadCompletely();"/>

Here I have placed the Licence Agreement text in another html file and placed it in a iframe, you can directly place the Licence Agreement Text in the division.

<script language="javascript">

var blnPinScrollbar = false;

function checkScrollPosition()
{
var divFrame = document.getElementById('frAgreement');
if(divFrame.scrollHeight - divFrame.scrollTop + 17 == divFrame.offsetHeight)
{
blnPinScrollbar = true;
}
}

function isReadCompletely()
{
if(blnPinScrollbar)
{
alert("Page is submited");
return true;
}
else
{
alert("Please read the agreement and click on submit.");
return false;
}
}
</script>

I have declared a global variable blnPinScrollbar which is set as false & whenever scroll event fires it will check whether the division is scrolled to the end (17 is the scrollbar up arrow height, this value may vary from user to user. Please try with different values if it didn't works for you.).

You can find sample page with the above example at - http://vijjub4u.googlepages.com/main.html

Feel free to mail me at vijjub4u@gmail.com if you have any problems/issues with this solution.

This sample can also be used for checking whether a division / text box / scrollable control is scrolled are not.

Thursday, October 25, 2007

Debug JavaScript

Most of the time developers uses alert('message'); to debug the JavaScript. But its not that much efficient because whenever you want to change the property of an object you have to change the code & re-run the application.

One keyword available in JavaScript which will enable us to debug the JavaScript as we do in our .Net (will have intellisense), by this we can see all the properties & function available in the object.

Steps to Debug JavaScript:

  1. Identify the debugging point & place 'debugger;' keyword in the JavaScript code.
  2. Open IE (Internet Explorer) - Go to Tools -->Internet Options -->Advanced Tab
  3. Deselect the below mentioned two check boxes.
    • Disable script debugging (Internet Explorer)
    • Disable script debugging (Other)Debug Javascript - IE Settings
  4. Run the application (for which you want to debug). If you are developing .Net application Visual Studio .Net IDE will automatically jumps to debugger position. Start using the intellisense & resolve you issues.Debug Javascript
  5. If you are not using Visual Studio IDE, one window will prompt to select debugger engine with all available JavaScript debugger engines in you system. Some times even Visual Studio IDE will also prompt for the debugger.Debug Javascript - Select Debug Engine
  6. Select any of the Debugger engine and start debugging the JavaScript.

Solution for Visual Studio .Net - Error file name & line numbers are not getting displayed.

I think most of the developers are came across this situation where they can see the file names & line numbers of the errors after building/compiling the code. This is very annoying thing in Visual Studio IDE. I don't know why the Microsoft guys unable to resolve this issue.

I too came across this issues & after googled I found this solution.

The issue is if you have the parenthesis ( '(' or ')' ) in the file path, it won't show you the file name & line number.

To solve this you have to rename that folder name.

Tuesday, October 9, 2007

Failed to access IIS metabase Error - Solution 2

This type of problem will occur if you have installed iis after installing framework.

Solution is uninstall & install the framework (2.0).

thanks,

vijju

Disable right click on web page

Hi Friends,

Here is the small JavaScript function to disable right click.

//register right click event (mouse click)

document.onmousedown = disableclick;
//function

function disableclick(e)
{

if(event.button==2)
{
alert("Right Click Disabled");
return false;
}
}

thanks,

vijju

Failed to access IIS metabase Error - Solution 1

This type of problem will occur only if you have both 1.1 & 2.0 Framework installed on your system. (along with the associated Visual Studio 2003 and 2005 products because you can't help but write software in both environments).

Upon running your website (via http://localhost/xxx or something like that), you may encounter the error page that reports:

Failed to access IIS metabase

If so, you may have installed IIS after installing the .NET framework.  If that's the case, try running to repair your ASP.NET installation and set up all of the appropriate ISAPI extension mappings.

aspnet_regiis -i

If, however, you're like me and had IIS already installed, and you installed VS 2003 and then VS 2005, and then set up a 1.1 virtual directory / website, simply check that the appropriate ASP.NET version is associated with it (Select VDIR --> Properties --> ASP.NET tab).

"aspnet_regiis -i"  - However, the directory it is located in was not included a system path previously, so just note that you may have to run this from the "WINDOWS\Microsoft.NET\Framework\vX.X.XXXXX" directory (with the X's being your version number) .

thanks,

vijju

Visual Studio Clipboad Ring - Tip

Unlike most other applications, VS.NET has something called a clipboard ring.
During development, the average developer finds it very annoying that you can only save 1 item into the clipboard (copy-and-pasting).
Well with VS.NET, the clipboard ring allows you to save up to 20 items into the clipboard. To reference this items, its important to know that they are saved in a LIFO method (Last-In First-Out if your not into stacks).
Usage:
1. Copy a selection using Ctrl-C (Copy). You can repeat this copying upto 19 more times.
2. Pressing Ctrl-V will paste the last item you copied. Nothing new yet right?
3. Pressing Ctrl-Shift-V will also paste the last item in the clipboard.
Now say you want to retrieve the 2nd, or 3rd last item you inserted into the clipboard, simply keep pressing Ctrl-Shift-V to cycle through the items in the clipboard.
So this saves you from running back and forth between documents to get the next selection of text you want to paste over to some other page of code.

Wednesday, September 12, 2007

Database Diagrams Error - SQL Server 2005

Hi Friends,

Most of our friends will receive the below error message when they are trying to create a database diagram. This will happne when the database


Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.


This is covered in section 4.8 in the Readme file that comes with the product .To install database diagram support in SQL Server Management Studio, databases must be in SQL Server 2005 database compatibility level. Database compatibility level can be reset after diagram support is installed. To create database diagrams, change the database compatibility level to 2005, install database diagram support, and then return the database to the desired database compatibility level. For more information, search for "sp_dbcmptlevel" in SQL Server Books Online.So, run the following statement and try the diagram again.

EXEC sp_dbcmptlevel database_name, 90

I happened to have the SQL 2005 server DVD in my player, and I found aReadme in G:\SQL Server x86\Servers\ReadmeSQL2005.htm. There seem to beone in every top-level setup directory.

Otherwise run this command.....

ALTER AUTHORIZATION ON DATABASE::<databsae> TO <username>

More info at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;910228