Tuesday 27 December 2011

How to get current URL / Request.Url in Javascript?

Definition: The href property returns the entire URL of the current page.

Code:
      function GetURL()
      {
        var Url = document.location.href;
       alert(Url);
      }

Wednesday 21 December 2011

How to clear TextBox value using javascript?

Definition: Clear TextBox value.
To clear TextBox value we will use onclick() event of TextBox. onclick() we will call user defined javascript function.

Code:
1. First put TextBox control on page.

<asp:TextBox ID="TextBox1" runat="server" Text="Your Text Here" onclick="javascript:Clear(this);"></asp:TextBox>

2. Now write onclick() event as shown above.

3. Now in Head tag we will write javascript function.

<head runat="server">
    <title>Form validation</title>
    <script language="javascript" type="text/javascript">
                  function Clear(txt)
                {
                         txt.value="";
                 }
  </script>
</head>

4. When user click inside the TextBox its value will be clear.





Tuesday 20 December 2011

How to generate random password in Asp.Net / C#.Net?

Definition: Generate Random Password.

Code:
private string GeneratePassword(byte Length)
    {
        char[] Chars = new char[] {
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
        };
        string String = string.Empty;
        Random Random = new Random();

        for (byte a = 0; a < Length; a++)
        {
            String += Chars[Random.Next(0, 61)];
        };

        return (String);
    }

How to call GeneratePassword method?

string pwd = string.Empty;
//generate random password
pwd = GeneratePwd(8);  //we have to pass length of password. you can pass any length


Friday 2 December 2011

How to prepare masala bhindi?

Ingredients for stuffed bhindi:





500 gm Okra (Bhindi), washed and dried
3 tbsp - oil
1 tsp cumin seeds (jeera)
1 medium sized onion, chopped
2 green chilies, seeded and chopped
3/4-inch ginger, finely chopped
A pinch of Asafetida powder
1 tomato chopped

For Stuffing :
3 tsp coriander powder
2 tsp turmeric powder
2 tsp ground fennel (saunf)
2 tsp dried mango powder (amchur) / or you can use 1tsp lemon juice
1/2tsp chili powder or to taste
Salt To Taste 
For Garnishing:
Coriander leaves
Preparation of stuffed okra:
  1. Cut the stalk of each okra and make lengthwise slit.
  2. Combine stuffing ingredients and mix well. Stuff each okra with the mixture.
  3. Sauté cumin with the little oil until it starts to crackle.
  4. Add onions, green chilies and ginger. Sauté till onion turns transparent, then put in asafetida and cook for a few seconds.
  5. Add tomato and cook until it turns pulpy.
  6. Add the okra and cook for 5 minutes until tender and well coated with the sauce (masala). 
  7. Now put off the flame and garnish with coriander leaves. 
  8. Serve stuffed bhindi hot with chapati,rice or paratha.

How to Create File in C#.net?

File.Create Method (String)
Creates or overwrites a file in the specified path.

Code:
Add Namespace:  System.IO

using System.IO;

protected void btnCreate_Click(object sender, EventArgs e)
    {
        string ls_FilePath = "G:\\";
        string ls_FileName = txtFilename.Text + ".txt";

        try
        {
            File.Create(ls_FilePath + "\\" + ls_FileName);
            lblmsg.Text = "File Created";
        }
        catch(Exception ex)
        {
            lblmsg.Text = ex.Message;
        }
       
    }

How to show image in GridView in Asp.net?

Show image in Gridview control.

Code:

1. First Create Table with following structure:

CREATE TABLE [Image1]
(
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [ImageName] [varchar](50) ,
    [Description] [varchar](50)
)

2. Now insert GridView control on your ASPX page and set the following properties as show below.

        <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
            CellPadding="4" ForeColor="#333333" GridLines="None">
              <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
              <RowStyle BackColor="#EFF3FB" />
              <Columns>
                <asp:TemplateField HeaderText="id">
                    <ItemTemplate>
                    <asp:Label ID="lblEmpCode" runat="server" Text='<%#    DataBinder.Eval(Container.DataItem, "ID")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                    <ItemTemplate>
                        <asp:Label ID="lblEmpName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageName")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="image">
                    <ItemTemplate>
                        <asp:Image ID="myImage" runat="server" Height="25" ImageUrl='<%# DataBinder.Eval ( Container, "DataItem.ID", "~/Images/{0}.jpg" ) %>' />
                    </ItemTemplate>
                </asp:TemplateField>
              </Columns>
             
              
              <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
              <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
              <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
              <EditRowStyle BackColor="#2461BF" />
              <AlternatingRowStyle BackColor="White" />
        </asp:GridView>

3. Fill grid. You can use following code or your own code to fill grid with database table.
    Please set "WebConnectionString" connection string according to your SQL Server.
    Add Namespace: using System.Data;

 private void FillGrid()
    {
        string ls_SQL = string.Empty;
        string ls_Constr = string.Empty;
        SqlConnection cn;
        SqlDataAdapter adp;
        DataTable dtImage = new DataTable();

        try
        {
            ls_SQL = "SELECT  id,imagename,description FROM Image";
            ls_Constr = ConfigurationManager.ConnectionStrings["WebConnectionString"].ConnectionString;
            cn = new SqlConnection(ls_Constr);
            cn.Open();
            adp = new SqlDataAdapter(ls_SQL, cn);
            adp.Fill(dtImage );
            if (dtImage .Rows.Count > 0)
            {
                GridView3.DataSource = dtImage ;
                GridView3.DataBind();
            }
            cn.Close();
        }
        catch (Exception ex)
        {
        }
    }

4. Output:


5. Note: 
I have save my images in Images folder in Application Path

Here you can see 1.jpg,2.jpg,3.jpg and 4.jpg . I have save them with same ID as in the table.

Friday 18 November 2011

Start New Line in JavaScript alert box

How to start New Line in JavaScript alert box?

Code:

 \n is used to start with new line.

alert("Your message successfully sent.\nThanks for contacting.");
 
output:
 
Your message successfully sent.
Thanks for contacting. 

 

onfocus event

OnFocus event. Sometimes you want to clear text when user click in TextBox.

Definition:
The onfocus event occurs when an object gets focus.

Code:
Following the javascript.

<script type="text/javascript">
      function Focus(a)
     {
            if(a.value = = a.defaultValue)
                 a.value = "";
     }
</script>

HTML Code:

<input type="text" value="Email ID"  onfocus="Focus(this)"  id="txtEmail" name="txtEmail" />
 


onblur event

OnBlur event. Sometimes you want to show default value in TextBox when it is empty.

Definition:
The onblur event occurs when an object loses focus.


Code:
Following the javascript.

<script type="text/javascript">
      function Blur(a)
     {
             if(a.value = = "")
                  a.value = a.defaultValue;
     }
</script>

HTML Code:

<input type="text" value="Email ID"  onblur="Blur(this)"  id="txtEmail" name="txtEmail" />

Friday 11 November 2011

How to Move Directory or Rename Directory in C#.Net?

How to Move Directory or Rename Directory in C#.Net?

First add System.IO;

Code:
  string NewName= string.Empty;
  NewName = "RenameFolder";
  Directory.Move("F:\\myFolder", "F:\\" + NewName);

This will move your directory to new directory.


Tuesday 8 November 2011

How to prepare Aalu Poha?

Title: Aalu Poha

Ingredients:

  • 2 cups Poha (Beaten Rice) 
  • 1 Potatoes 
  • 1 Onions 
  • 2 Green Chillies 
  • 1/4 tsp Mustard Seeds
  • 1 sprig Curry leaves
  • 2 tsp Peanuts (optional)
  • 4 tblsp Oil 
  • 1 pinch Turmeric powder 
  • 1 Lemon
  • Few Corainder leaves 
  • Salt to taste 

How to make aloo poha : 

• Soak the poha in water. Wash and drain all the water.
• Add some salt, turmeric powder and keep aside.
• Peel and cut the potatoes into small cubes, chop the onions, chillies, corainder leaves.
• Heat oil and put mustard seeds, peanuts, curry leaves and fry until they crackle.
• Add potatoes, sauté for few minutes, then add chopped onions, chillies. Add little salt because we have already put salt in poha.
• Cook till they are done. Add the poha and stir.
• Keep it on slow flame for 5- 7 minutes.
• Now add lemon juice.
• Garnish with coriander leaves.

Notes:
 
Friends you can also try some other variation of Poha.
1. In green peas seasons you can add green peas with potato.
2. If you like sugar, you can also add 1tsp sugar after when we wash poha.
3. Garnish with grated fresh coconut, fried peanuts.
4. You can also garnish with Sev which more popular in Madhya Pradesh.

Monday 7 November 2011

Comedy circus ka naya daur 6th November 2011


Comedy circus ka naya daur 5th november 2011


How to rename directory in .Net

There is no separate method for renaming the folders in c#.Net. But you can achieve this by using Move method which is in Directory class.
Note: using System.IO namespace.
string path = System.Configuration.ConfigurationSettings.AppSettings["Path"].ToString();
string Fromfolder;
string Tofolder; Fromfolder ="\\"+Fromfolder+"\\";
Tofolder = "\\"+Tofolder+"\\";
Directory.Move(path + Fromfolder, path + Tofolder);