Perform Specific Button click event when user press Enter key in Textbox

Put your form inside an asp.net panel control and set its DefaultButton attribute with your button ID. See the code below:

 

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
         <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Send" />
             </ContentTemplate>
          </asp:UpdatePanel>
</asp:Panel>

Visual Studio 2013 Change the Default Location for Projects

For corporate office user my document is always redirected to a file server where creating exe file is restricted.

1. Create a folder in c drive called: vs 2013

2. Inside that folder create 2 folders

Projects

Templates

3. Inside Templates, create another 2 folders:

ItemTemplates

ProjectTemplates

4. Open visual studio and follow the steps

  • On the Tools menu, select Options.
  • From the Projects and Solutions folder, select General.
  • In the Visual Studio projects location text box, enter a location for files and projects.

 

vs2013

 

And you should be all set.

 

Configure visual studio to use youtube API

Install youtube api for your application first:

y1

y2

 

PM> Install-Package Google.Apis.YouTube.v3

 

Add the following code in your cs file:

 

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

 

Further details:

 

https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth

 

 

Remove HTML tags in String in C#

If the string is like that

string s = “"<p>hello <b>there</b></p>"

 

Use the regular expression:

 

using System.Text.RegularExpressions;
...

static string StripHTML (string inputString)
{
   return Regex.Replace 
     (inputString, "<.*?>", string.Empty);
}


But if the input string is like this:

String s = "&lt;/b.......&gt;"

You need to decode it first using http utils as follows:

Add a sub functiona and pass the input string to that to decode the string and use the regular expression avobe.

public static string DecodeHtmlEntities(string text)
    {
        return HttpUtility.HtmlDecode(text);
    }


Sort Numeric DataTable

DataView dv = new DataView(dt1);
dv.Sort = "CalculatedPriceWithNoSymbol ASC";
dataGridView.DataSource = dv.ToTable();
By simplemsexchange Posted in C#

Add a new DataTable column with type “Integer”

  1. Dim dt As New DataTable
  2.         dt.Columns.Add(New DataColumn(“Task”, GetType(String)))
  3.         dt.Columns.Add(New DataColumn(“View_Order”, System.Type.GetType(“System.Int64”)))
  4.         dt.Columns.Add(New DataColumn(“Completed”, GetType(Boolean)))
By simplemsexchange Posted in C#

How To Sort Datatable in c#.net

DataTable dt = new DataTable();
dt.Columns.Add("Date", typeof(DateTime));
dt.Columns.Add("Preferance", typeof(int));
 
dt.Rows.Add("30/07/2011", 0);
dt.Rows.Add("02/03/2011", 1);
dt.Rows.Add("10/12/2011", 2);
dt.Rows.Add("01/12/2011", 3);
 
DataView dv = new DataView(dt);
dv.Sort = "Date ASC";
 
for (int i = 0; i < dv.Count; i++)
{
    Console.WriteLine(Convert.ToDateTime(dv[i]["Date"]).ToString("dd/MM/yyyy") + "\t" + dv[i]["Preferance"]);
}

DropDownList SelectedIndexChanged not firing

Set the AutoPostBack = “True” for the listbox.

 

Markup

<asp:DropDownListID=”DropDownList1″runat=”server”AutoPostBack=”true”
OnSelectedIndexChanged=”DropDownList1_SelectedIndexChanged”>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>

CodeBehind 

ProtectedSub DropDownList1_SelectedIndexChanged(ByVal sender AsObject, ByVal e As System.EventArgs)
Response.Write(DropDownList1.SelectedIndex)
EndSub

Check Valid Email Function using C# and VB.NET

C#:

bool IsValidEmail(string email)
{
    try {
        var addr = new System.Net.Mail.MailAddress(email);
        return true;
    }
    catch {
        return false;
    }
}




VB:

Private Function IsValidEmail(ByVal email As String) As Boolean
        Try
            Dim addr = New System.Net.Mail.MailAddress(email)
            Return True
        Catch
            Return False
        End Try
    End Function
By simplemsexchange Posted in C#, VB.NET