Showing posts with label VisualStudioTips. Show all posts
Showing posts with label VisualStudioTips. Show all posts

08 June 2012

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
Use <%# this.txtCompany.ClientID %> to replace <%= this.txtCompany.ClientID %> to fix the problem.

Once those changes are done then run the application if your not getting the values of controls(getting balnk ("") value instead of Client id) then follow the below step.

Re-place (<%# ... %>) with (<%= ...%>) and put your script from "head" tag to "body" tag.


Ref Link:- 
http://www.west-wind.com/weblog/posts/2006/May/27/The-Controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie-
http://www.dotnet-tips.com/2006/09/controls-collection-cannot-be-modified.html

18 May 2012

Data Cache in ASP.NET

Most of the times we need to store large amounts of data client side is by using the ViewState. It will only exist on the page you add it to though. So if you are jumping around from page to page it won't really work. In that case you really should be using Session or Application Cache depending on your scenario.


ViewState:  
 ViewState is one of the techniques that Asp.net provides in order to save the data for latter use. The important fact about the ViewState is that it can only save the values for page level access. It means that if I save something on page1.aspx using Viewstate I cannot access it on the page2.aspx using the same technique. For this reason ViewState is only used to save the values for the page level access which should be maintained after post backs.Whenever we write anything in the ViewState object a hidden field is created in the page. After the post back it will display the value of the dataset using the ViewState control.

So if you are doing something where you are always on the same page and just doing many PostBacks for things like paging or sorting then ViewState will work fine but do realize you will be passing large amounts of data back and forth to the server each time a PostBack is made.
Example Using ViewState:

// Set it
ViewState["dsViewEmp"] = dsEmployee;


// Get it
DataSet ds = ViewState[" dsViewEmp "] as DataSet;


Session and the Application Cache are accessed the same way. Just replace ViewState with the word Session or Cache.


What is Data Cache?
Data Cache is used to storing frequently used data in the Cache memory. It's much efficient to retrieve data from the data cache instead of database or other sources. We need use System.Web.Caching namespace. The scope of the data caching is within the application domain unlike "session". Every user can able to access this objects.


How data caching is work?
When client request to the server, server execute the stored procedure or function or select statements on the Sql Server database then it returns the response to the browser. If we run again same process will happen on the web server with sql server.
In the very first time retrieve the records from the sql server database and stored into the Cache memory.  After that records will retrieve from Cache memory (IIS). We can set expiration period time after expiration time over the caching again it will hit the sql server database and stored into the cache memory and next retrieve will happen on the data cache memory.


Advantages of Cookies
Following are main advantages of using cookies in web application:
It's very simple to use and implement.
We can avoid database hitting.
We can reduce network traffic.

How to create data cache? 
Cache["Employee"] = dsEmployee


We can create data caching use Cache Keyword. It's located in the System.Web.Caching namespace. It's just like assigning value to the variable


How to Read data from Data Cache?
Dataset dsEmployees = (Dataset) Cache ["Employee"]


This is very similar to assigning object to the Dataset.


Where does Data Cache are stored?
This is one of the interesting things to find out the Data Caching in your local drive. First of all, From "IE Internet Option ", delete Browsing History to clear Cache. 


How to remove a Data Cache? 
We can remove Data Cache manually.

//We need to specify the cache name


   Cache.Remove(String key);



Conclusion:
When it comes to choosing between ViewState and Caching it all comes down to what you are doing. ViewState is an ideal candidate if you are planning to save small values. Mostly values of server controls are saved in ViewState. If you plan to store large datasets, datatables or collections than data caching is an excellent candidate.


ReferenceLinks:
1. http://www.highoncoding.com/Articles/69_View_State_vs_Data_Caching.aspx
http://msdn.microsoft.com/en-us/library/z1hkazw7%28VS.80%29.aspx






30 October 2011

How to not show Visual Studio line numbers for blank lines?

Is there a way to display only line number of coded lines, i.e. don’t number blank lines? Numbered blank lines makes showing code in powerpoint decks hard to follow. 
 
Here’s the screenshot 
To do this,
  1. Enable Word Wrap (Tools Options – Text Editor – All Languages – General)
  2. At the end of the first real line (like #28 above), start inserting white space until it goes off the screen. Note the Word Wrap glyph.
  3. Turn off the Word Wrap glyph (same place as in step 1) and Turn off “View White Space” (Edit – Advance – View White Space)

21 October 2011

Visual Studio 2008 styles

Visual Studio allows you to completely customize the editor background and text colors to whatever you want – allowing you to tweak them to create the experience that is “just right” for your eyes and personality.  You can then optionally export/import your color scheme preferences to an XML file via the Tools->Import and Export Settings menu command.
  
A New website that makes it easy to download and share VS color schemes

Luke Sampson launched the http://studiostyles.info/ site a week ago (built using ASP.NET MVC 2, ASP.NET 4 and VS 2010). Studiostyles.info enables you to easily browse and download Visual Studio color schemes that others have already created.  The color schemes work for both VS 2008 and VS 2010 (all versions – including the free VS express editions):

You can click any of the schemes to see screen-shots of it in use for common coding scenarios.  You can then download the color settings for either VS 2010 or VS 2008: This site is cool and you can find lots of visual studio 2010 and 2008 styles of your choice. 



I have downloaded the first one(Son of Obsidian). It will be visual studio settings file. 


Once you downloaded you can import like following. GoTo Tools->Import and export settings in Visual Studio 2008. Once you click this It will import and export dialog like following.

I have selected Import selected environment setting and clicked next on next screen you will have option to save your visual studio settings like following.

Clicking on next you will have options for different visual studio 2008 Style like following.

 Click on browse and select your downloaded style like following.

Click on open and then you will represented to recent file options

Click next You will come to final settings wizard like following.


 Click on finish now our style is applied.Close the dialog and open your project and you can see new color scheme for your visual studio 2008 like following.

How to Open Visual Studio Quickly?

Do the following simple steps.
Open Your Visual Studio by typing 'Start' --> 'Run' --> 'DEVENV' then,

1. Click Tools
2. Select Options.
3. Expand Environment.
4. Click Startup.
5. Choose Show Empty Environment in the dropdown for At startup.
6. Disable the Download Content Every checkbox
7. Click OK.  as shown in the below screen shot. 


02 December 2010

How to Display Line Numbers in Visual Studio

Show Line Numbers in Visual Studio

It is always better to have Line numbers displayed in Visual Studio when you debug your VB or C# Project. It is not turned on by default. Select tools form the tool bar and select options tab and then you can turn it on as shown below.

29 November 2010

Debugging Shortcut in visual studio 2005

Ctrl-Alt-V, A
Displays the Auto window to view the values of variables currently in the scope of the current line of execution within the current procedure
Ctrl-Alt-Break
Temporarily stops execution of all processes in a debugging session. Available only in run mode
Ctrl-Alt-B
Displays the Breakpoints dialog, where you can add and modify breakpoints
Ctrl-Alt-C
Displays the Call Stack window to display a list of all active procedures or stack frames for the current thread of execution. Available only

in break mode
Ctrl-Shift-F9
Clears all of the breakpoints in the project
Ctrl-Alt-D
Displays the Disassembly window
Ctrl-F9
Enables or disables the breakpoint on the current line of code. The line must already have a breakpoint for this to work
Ctrl-Alt-E
Displays the Exceptions dialog
Ctrl-Alt-I
Displays the Immediate window, where you can evaluate expressions and execute individual commands
Ctrl-Alt-V, L
Displays the Locals window to view the variables and their values for the currently selected procedure in the stack frame
Ctrl-Alt-M, 1
Displays the Memory 1 window to view memory in the process being debugged. This is particularly useful when you do not have debugging

symbols available for the code you are looking at. It is also helpful for looking at large buffers, strings, and other data that does not display clearly in

the Watch or Variables window
Ctrl-Alt-M, 2
Displays the Memory 2 window
Ctrl-Alt-M, 3
Displays the Memory 3 window
Ctrl-Alt-M, 4
Displays the Memory 4 window
Ctrl-Alt-U
Displays the Modules window, which allows you to view the .dll or .exe files loaded by the program. In multiprocess debugging, you can

right-click and select Show Modules for all programs
Ctrl-B
Opens the New Breakpoint dialog
Ctrl-Alt-Q
Displays the Quick Watch dialog with the current value of the selected expression. Available only in break mode. Use this command to

check the current value of a variable, property, or other expression for which you have not defined a watch expression
Ctrl-Alt-G
Displays the Registers window, which displays CPU register contents
Ctrl-Shift-F5
Terminates the current debugging session, rebuilds if necessary, and then starts a new debugging session. Available in break and run

modes
Ctrl-Alt-N
Displays the Running Documents window that displays the set of HTML documents that you are in the process of debugging. Available in

break and run modes
Ctrl-F10
Starts or resumes execution of your code and then halts execution when it reaches the selected statement. This starts the debugger if it is

not already running
Ctrl-Shift-F10
Sets the execution point to the line of code you choose
Alt-NUM *
Highlights the next statement to be executed
F5
If not currently debugging, this runs the startup project or projects and attaches the debugger. If in break mode, this allows execution to

continue (i.e., it returns to run mode).
Ctrl-F5
Runs the code without invoking the debugger. For console applications, this also arranges for the console window to stay open with a

"Press any key to continue" prompt when the program finishes
F11
Executes code one statement at a time, tracing execution into function calls
Shift-F11
Executes the remaining lines of a function in which the current execution point lies
F10
Executes the next line of code but does not step into any function calls
Shift-F5
Available in break and run modes, this terminates the debugging session
Ctrl-Alt-V, T
Displays the This window, which allows you to view the data members of the object associated with the current method
Ctrl-Alt-H
Displays the Threads window to view all of the threads for the current process
F9
Sets or removes a breakpoint at the current line
Ctrl-F11
Displays the disassembly information for the current source file. Available only in break mode
Ctrl-Alt-W, 1
Displays the Watch 1 window to view the values of variables or watch expressions
Ctrl-Alt-W, 2
Displays the Watch 2 window
Ctrl-Alt-W, 3
Displays the Watch 3 window
Ctrl-Alt-W, 4
Displays the Watch 4 window
Ctrl-Alt-P
Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes

31 October 2010

Resetting VS Language Settings

Resetting your Default Language Settings in VS 2005 
After you have installed Visual Studio 2008/2005  you are prompted to ‘choose’ the default collection of settings for your environment.  Depending one what choice you chose will dictate your keyboard mappings, your menu options, etc.

What do you do if you don’t like your selection after the initial install or if you want to change them?  You can change them, but it is not intuitive.
Here are the steps to change your settings:
  1. Choose Tools -> Import and Export Settings...
  2. Select Reset All Settings and click Next
  3. Select whether you would like to save the current settings (I would say not here) and click Next
  4. Select the settings you want to use and click Finish
  There you have it, the steps to reset/change your default language settings…