.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Working with Code Snippets in VS.NET

Posted By: hajan     Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
INTRODUCTION Creating code snippets using VS.NET is very useful tip because it may help you when you need to write code repeatedly within your applications. For instance, we may use try catch finally block very often. Rather than writing the complete code-block manually, we may save it as a Code Snippet, then use it anywhere we want. In this blog post, I will show you how to create, save and use Code Snippets, where you will see why Code Snippets are extremely useful, especially if you know that you may have various cases where you will apply such or similar code-blocks. WORKING WITH EXISTING VS.NET CODE SNIPPETS Microsoft has provided us with code snippets that developers use in most of the cases. In order to see the already existing code-snippets, in code-behind of your .net application, use the following shortcut keys: CTRL+K+X Insert Snippet will appear you can select one of the given folders, and some predefined code snippets will appear The line above the snippets shows the path to the snippet (1) where you can write the shortcut key of the snippet you want to insert (for faster approach). In our case, we select the try (2) snippet, which will insert the following code:         void MyMethod()         {            &nbs

View Complete Post

More Related Resource Links

Free Code Snippets - ASP.NET

You Can Find Useful ASP.NET Related Posts on the above link.

Free Code Snippets - C#

Free C# Code Snippets

Toolbox: Microsoft Chart Controls, Visual Studio Automatic Code Snippets, And More


In this installment we look at the Microsoft Chart Controls; Snippet Designer, a free, add-in for Visual Studio 2008 for creating and editing Code Snippets; refactoring SQL applications; and this month's favorite blog.

Scott Mitchell

MSDN Magazine April 2009

Advanced Basics: IntelliSense Code Snippets


IntelliSense code snippets are one of the coolest new features in Visual Studio® 2005. Code snippets are highly customizable code fragments intended to accomplish simple to intermediate tasks quickly; they can be inserted into your code with just a few keystrokes.

Lorenzo Minore

MSDN Magazine April 2006

Code write file asp.net 2.0 is working in firefox but IE not working.

If Not IsDBNull(ext) Then                                        ext = LCase(ext)                                    End If                                    Select Case ext                                        'Case ".htm", ".html"                                        '    type = "text/HTML"                   

Convert VB Code to working C# code

Hello. I am a beginner and I'm trying to work my way through the MSDN  beginner tutorials. The lesson I am working on had to do with transferring info to another page using a Session object. The example video is written in VB code. I tried to write this part of the lesson in C# code and where the VB code works I am getting an Error message in C# code saying 'The name 'Session' does not exist in the current context' and hence the program will not compile. here is VB Code on default.aspx page     Protected Sub nextButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles nextButton.Click     Dim bill As New Billing bill.FirstName = firstNameTextbox.Text Session.Add(   "billingInformation", bill) Response.Redirect(   "SessionResult.aspx") End Sub VB SessionResult.aspx code is:     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     Dim bill As Billing = Session("billingInformation")     Dim sb As New System.Text.StringBuilder() sb.Append(   "First Name: ") sb.Append(bill.FirstName) sb.Append(   "<br>") Response.Write(sb.ToString())     End Sub My C# code looks like this for default.aspx page and SessionResult.aspx page &nb

Ldap authenication code is not working with IIS but works with Visual Studio developement webserver

Hi,I have weird issue here, I have a method that  takes a login Id and authenticates with LDAP active directory and returns the employee Id.It works great when I run the application in Visual studio 2008 ( it uses the default visual studio developement webserver). The code authenitcates the login id and returns emp Id perfectly. But the problem comes when I publish the code to the Local IIS in my developement PC.public string GetEastWestTeamMembersEmployeeID(string loginID)        {            string domain = string.Empty;            string login = string.Empty;            int position = loginID.IndexOf(@"\");            string empid = "";                  System.DirectoryServices.DirectoryEntry directoryEntry = null;            if (position >= 0)            {                domain = loginID.Substring(0, position);    &n

Code in an event handler not working when used with system reflection.

Hi, I am presently writing an application that uses an MDI form with a ToolStrip on it. I have the need to build the menu items dynamically using an XML file. The format of the XML file is as follows: <ContextMenu EventHandlerHost="vFrmPDUsetup"> <!-- These styles will be applied to the menu items. Individual menu item styles can be override by defining as an attibute to the specific menu item, see below --> <Style> <MenuStripBackColour>Transparent</MenuStripBackColour> <BackColour></BackColour> <ForeColour>Chartreuse</ForeColour> <BackImage></BackImage> <!-- Must exist in Images folder --> <FontName>Tahoma</FontName> <FontSize>10</FontSize> <FontStyle>Bold</FontStyle> </Style> <!-- Attributes: Key = Resource Key name in resource file Image = image to display before text, image must exist in Images folder BackImage = background image, image must exist in Images folder BackColour = background colour as colour name ForeColour = foreground colour as colour name FontSize = size of font as value Seperator = add a menu seperator OnClick = click event pointing to the event handler method which must be defined as the MenuItem_ + <attibute value> &

Format Code D0 is not working in SSRS 2008


We are trying to migrate all our RDL from SSRS 2005 to SSRS 2008.

In the rdl’s we defined format code for a  text box as “D0”  which is working fine in SQL 2005.

While migrating the rdl’s to 2008 it is not working and data is showing for that text box as “#Error”.

How to resolve this . I am having around 1000+ rdl’s to update with proper format string.

If I open the Rdl in BIDS I am getting below error.


[rsInvalidFormatString] The Format value for the textrun ‘textbox1_0_13.Paragraphs[0].TextRuns[0]’ is not valid. Format specifier was invalid.

[rsRuntimeErrorInExpression] The Value expression for

Help Needed working our sp from vb.net code behind


I have a formview and am trying to run this code behind but keep getting this error

Procedure or function 'spCBI_ClientUpd' expects parameter '@op_status', which was not supplied


    Protected Function UpdateClientAdmin() As String
        ' SP UPDATE ClientAdmin 

        Dim ReturnValue As String = String.Empty
        Dim SQL_Connection As New SQL.SqlConnection
        Dim SQL_Command As New SQL.SqlCommand
        SQL_Connection = New SQL.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("CashbacsMainConnectionString").ConnectionString)
            SQL_Command.CommandText = "CASHBACSMAIN.dbo.spCBI_ClientUpd"
            Dim pLicence As New SQL.SqlParameter("@Licence", Data.SqlDbType.VarChar, 6)
            pLicence.Value = TxtLicence.ToString
            pLicence.Direction = Data.ParameterDirection.Input

            Dim pCompany As New SQL.SqlParameter("@CompanyName", Data.SqlDbType.VarChar, 6)
            pCompany.Value = CType(FormView1.FindControl("CompanyNameTextBox"), TextBox).Text
            pCompany.Direction = Data.ParameterDirection.Input

AJAX DropDownList won't populate.. error500.. code is working though.


Here's what I have.  I was able to debug and traverse through the webservice and return teh array back into the first call method of: return new CarsService()..  But back in the page_load method, I can't get it to update and show up in the page.  what am I doing wrong?!?!


<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
                     Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"  

Code behind feature not working



I am using WSS 3.0 on Win 2003 and SPD 2007.

I have created a list and created a customized the corresponding NewForm.aspx to with different sub headings as there are many columns and named it NewForm_v2.aspx. To this I've added a label and button to test code-behind features.

The problem:

I have created built a class library in VS2005 > assigned the key etc and finished all other formalities. Changed inheritance tags as well in NewForm_v2.apsx. But when I press the button it is not invoking the method present in the class library (The button should change the text in the label)

My next question is how to debug my code-behind? I've read some articles and tried, but could not hit my break point yet ...

Thanks for your help!


Code working in Xp bur showing Error in Vista


Hi all.


I am saving two data, One is date and other one is time in SQL server 2005 using asp.net ( VB.net).

I am saving this using following command:

cmd.commandtext = "insert into TABLE1 values ('" + Now.toshortdatestring + "', '" + Now.toshorttimestring + "')"


now while i am using this code in Windows Xp its working properly but in Windows VISTA it is showing some "Data Conversion Error  from string to datetime". 

If i remove the single quotes [ ' ] from the command it is showing error in the value of date and time.

thanks all



SlideShow extender working with code behind in VisualBasic


what i am trying to achieve is a single image control with slideshow extender attached which when of the category option buttons are pressed the SlideService goes get the images for that category from the image folder sub folders and starts to display them -

i have got the code to work as to, the point that i have to hardcode the images  sub folders path in to the webmethod - but i want the image folder name to be passed as a parameter when the webmethod GetSlides is called - the code i have so far is

From the aspx page - (the category name will be a string retrieved from the button text when clicked

<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="category 1" />
<asp:Button ID="Button2" runat="server" Text="category 2" />
<asp:Button ID="Button3" runat="server" Text="category 3" />
<asp:Button ID="Button4" runat="server" Text="category 4" />
<asp:Panel ID="Panel2" runat="server&qu

Code working in XP / 32 bit won't work in Win 7 / 64 bit - "Input string was not in a correct forma


I'm working on a program in VS 2008 / XP 32 bit. So far everything has been working
fine in both XP 32 bit and Win 7 / 64 bit - until I introduced the following piece of

        private void DateFilter()
            // strDate = "MM/dd/yyyy";

            // convert strDate to yyyyMMdd
            strConvYear = strDate.Substring(6, 4);
            strConvMonth = strDate.Substring(0, 2);
            strConvDay = strDate.Substring(3, 2);
            strConvDate = convYear + convMonth + convDay; // yyyyMMdd
            intConvDate = Convert.ToInt32(strConvDate);

            // convert DateTimePicker (dtpSortDates) format yyyy-MM-dd to yyyyMMdd
            intDtpSortDates =

Mostly used and essential jQuery code snippets

These snippets are small but yet powerful and essential. These are mostly used jQuery code snippets/example which can be used in any project

Code Optimized Web Development Profile (VS 2010 and .NET 4.0 Series)

When you first run VS 2010 it prompts you to select an IDE profile to use. The profile you select will configure how tool windows are displayed/docked in the IDE by default and set the default keyboard shortcuts. You can then customize any of these settings by using the Tools->Options menu within the IDE and then override/change them. You can also later reset your profile and pick a different one by choosing the Tools->Import and Export Settings menu command.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend