vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Thursday, April 26, 2012

Get Java Script Variables values at code behind in asp.net


Introduction:

Here you have to see the process to get the JavaScript Variables values at sever side by using the below code..
First you have to write the script function to pass the value in variable..

Code:
<script type="text/javascript">
        function ret() {
            var t = document.createElement("INPUT");
            t.type = "hidden";
            t.name = "t";

            t.value = "Get the value on server side";
            document.forms[0].appendChild(t);
        }
    </script>

Then we need to call the function onclient click button event……

<asp:Button ID="Button3" runat="server" Text="Button"  OnClientClick ="ret();" />

Finally we get the data in code behind by using below code..

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim str As String
        str = Request.Form("t")
        lbltxt.Text = str
    End Sub
 I hope you like the easy way to get the JavaScript variable at code behind..
Post your comments.

Wednesday, April 25, 2012

Format Date and time in grid view


Introduction:

In this article we will see to display date and time in correct format in grid view.

In many cases when we display date or time in grid view its show either date with time or only time. But, our need is to follow some standard format to display.

In that case we need to follow some code before binding grid view…

In two ways we used to binding data in grid view,using either template field or bound field.

Template field:
For Display time
<asp:TemplateField HeaderText="Date">
 <ItemTemplate>
 <%#Eval("Date", "{0:HH:mm:ss}")%>
 </ItemTemplate>
</asp:TemplateField>

For Date
<asp:TemplateField HeaderText="Date">
 <ItemTemplate>
 <%#Eval("Date", "{0:dd-MM-yyyy}")%>
</ItemTemplate>
</asp:TemplateField>

Bound field
<asp:BoundField HeaderText ="date2" DataField =" Date" DataFormatString ="{0:t}" />
For date:
<asp:BoundField HeaderText ="date2" DataField ="Date" DataFormatString ="{0:d}" />

I hope you like this article….

Saturday, April 21, 2012

Delete all the cookies when user closes the browser window in asp.net


Introduction
This article we ll see about how to clear all cookies when user close the browser window..
This question everyone one rise in common forum site, How to clear cookies when user close browser window. The process and i found the way to clear the cookies using JavaScript.
Here i call the JavaScript in body event 'onbeforeunload'

In previous article i used this event show warning message to user before closing browser window. For your reference here i mention the link below..

  
Here i used same event to clear all cookies before user close the window. When i looking for  the code ,it’s very difficult  to clear the cookies generated by server side..
If you are generated cookies using JavaScript, then you can easily clear the cookies, but you created in server side, you have to follow the same method to delete the cookies. Here i share the method to delete the cookies..

JavaScript code:
function clrcook(e) {
        var evt = window.event ? event : e;
        if (evt.clientY < 0) {

            var thecookie = document.cookie.split(";")
            for (var i = 0; i < thecookie.length; i++) {
                var expires = new Date();
                expires.setUTCFullYear(expires.getUTCFullYear() - 1);
                document.cookie = thecookie[i] + '; expires=' + expires.toUTCString() + '; path=/';

            }

        }
    }


  
So Here you have to call the script in body tag event..
<body onbeforeunload="clrcook(event)">
</body>

When window closing the even has been fired and delete all the cookies i.e. set the expiry date. 

I hope you like this article..
Post your valuable comments here……

Thursday, April 19, 2012

Get a selected Dropdown list value in textbox in asp.net


Introduction:
Here simple method to show selected dropdown list value in textbox.
This process we can easily do coding on server side, but i some case without get any post back we can set the dropdown list value in textbox.
In that case by using JavaScript easily accomplish the process..
JavaScript:
<script type="text/javascript" >
    function change(id) {
        var txt;
        txt = id.value;
        document.getElementById("TextBox1").value = id.value;
         }
</script>

<asp:DropDownList ID="DropDownList1" runat="server" onchange ="change(this);">
    <asp:ListItem >Item1</asp:ListItem>
    <asp:ListItem>Item2</asp:ListItem>
    </asp:DropDownList>
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>

I hope you like 

Tuesday, April 17, 2012

New features added in ASP.Net 4 and visual studio 2010



Here download the pdf file to know the details about the new features added in asp.net 4 and visual studio 2010.This PDF file would help you to work with advanced feature in visual 2010..

This document provides an overview of many of the new features for ASP.NET that are included in the.NET Framework 4 and in Visual Studio 2010.


Wednesday, April 11, 2012

Display characters counter for multiline textbox in asp.net


Introduction:
In this article going to see about to display remaining character count in multiline textbox…
Normally this method used to display the remaining character user can able to enter in the textbox…
By limit to certain limit length, total length used to display using this method……


Java script Code:
<script type="text/javascript" language="Javascript">
        function textCounter(field, countfield, maxlimit) {
            if (field.value.length > maxlimit)
                field.value = field.value.substring(0, maxlimit);
            else
                countfield.value="charactes left ";
                countfield.value +=maxlimit - field.value.length;
        }
    </script>

<div>
         <asp:TextBox ID="TextBox1" runat="server" Height="100" Width="550" Wrap="true"
           TextMode="MultiLine" onkeyup="textCounter(TextBox1, TextBox2, 50);"
           onkeydown="textCounter(TextBox1,TextBox2, 50);" />   
    </div>
<div>
      <asp:TextBox ID="TextBox2"
          runat="server" style="color :Red;" ></asp:TextBox>
    </div>

I hope you like these easy methods to display character count…
Post your comments here…

Wednesday, April 4, 2012

Take Print only gridview data in asp.net


Introduction:
Here you will learn to print only grid view content in asp.net web page.

In a previous article I wrote to print a web page for you reference I given the following below..


Some case we need to print only grid view data, In that case we follow this method code..
Here I kept a grid view inside the panel, so when print we call directly the panel id to print..
First :
We have to create data table to bind in grid view.
Code:
DataTable dt=new DataTable();
    DataRow dr;
    DataRow dr1;
dt.Columns.Add("Name");
        dt.Columns.Add("mark");
        for (int i = 0; i < 5; i++)
        {
            dr = dt.NewRow();
            dr1 = dt.NewRow();
            dr["Name"] = i;
            dr["mark"] = i;
            dt.Rows.Add(dr);
            dt.Rows.Add(dr1);
}
GridView1.DataSource = dt;
        GridView1.DataBind();


Client side code:
<div>
        <asp:Panel ID="Panel1" runat="server">
         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false" CssClass ="td">
        <Columns >
        <asp:BoundField  HeaderText ="Name" DataField ="Name"></asp:BoundField>
        <asp:BoundField  HeaderText ="Mark" DataField ="Mark" />
        </Columns>
        </asp:GridView>
    </asp:Panel>
    </div>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick ="printItn();"/>
    </div>