Thursday, 27 February 2014

ASP.NET Insert Data in GridView EmptyDataTemplate with Example


In this article I will explain How to save GridView EmptyDataTemplate (Empty Data Template) Data in ASP.NET

To use a GridView control a DataSource control has to be attached to the GridView control. The property DataSourceID of the GridView control binds the GridView control to the DataSource control and allows paging, sorting and database operations with the DataSource. 

There are four popular DataSource controls and SqlDataSource control is one of them. We use SqlDataSource control, to attach the GridView control to the Sql Server Data base. 

But you couldn’t get any data from database you need to show Empty data row for saving first record to Database. On that time we need to use GridView EmptyDataTemplate.

Below is the design code for GridView EmptyDataTemplate.


Design:

What is gridview control in ASP.NET? What are the Templates and main Events in GridView.

In this article I will explain what is gridview control in ASP.NET? What are the Templates and main Events in GridView.

GridView:

The GridView control is a feature rich and versatile control used to accept, display, and edit data on a web page. It is a commonly used control in ASP.Net web applications. 

To use a GridView control a DataSource control has to be attached to the GridView control. The property DataSourceID of the GridView control binds the GridView control to the DataSource control and allows paging, sorting and database operations with the DataSource. 

There are four popular DataSource controls and SqlDataSource control is one of them. We use SqlDataSource control, to attach the GridView control to the Sql Server Data base. 

Sunday, 23 February 2014

Ajax FilteredTextBox with Example in ASP.NET


In this article I will explain what is Ajax FilteredTextBox with Example in ASP.NET.

FilteredTextBox is an extender which prevents a user from entering invalid characters into a text box. Note that since this effect can be avoided by deactivating JavaScript, you should use this extender as a convenience for your users, but you must never expect that the data being sent to the server consists of "valid" chars only.

Example 1:

<Ajax:FilteredTextBoxExtender ID="fteSoldDate" runat="server" TargetControlID="txtSoldDate" FilterType="Custom, Numbers" ValidChars="/+-" />

Example 2:

<Ajax:FilteredTextBoxExtender ID="fteInvoiceNo" runat="server" TargetControlID="txtInvoiceNo" FilterType="Custom, Numbers, UppercaseLetters, LowercaseLetters" ValidChars="" /></td>

Ajax CalendarExtender Example, Change date format and show calendar when click on button in ASP.NET


In this article I will explain what is Ajax CalendarExtender with Example, Change date format and show calendar when click on button in ASP.NET.

Ajax CalendarExtender:

Calendar is an ASP.NET AJAX extender that can be attached to any ASP.NET TextBox control. It provides client-side date-picking functionality with customizable date format and UI in a popup control. You can interact with the calendar by clicking on a day to set the date, or the "Today" link to set the current date.

Syntax:

<ajaxToolkit:Calendar runat="server"
    TargetControlID="Date1"
    CssClass="ClassName"
    Format="MMMM d, yyyy"
     />

Example:

<asp:TextBox runat="server" ID="txtInvoiceDate"></asp:TextBox>
<Ajax:CalendarExtender ID="CalendarExtender2" runat="server" Enabled="true" Format="dd/MM/yyyy"

                                                            TargetControlID="txtInvoiceDate">

Ajax AutoCompleteExtender example and sample without using webservice


 
In this article I will explain what Ajax AutoCompleteExtender example and sample without using webservice in asp.net.

We can attach Ajax autocomplete exteneder to any textbox to implement this and after assign autocomplete extender to textbox and type more content than the specified minimum word length, a popup will show words or phrases starting with that value.  So the user can choose exact word from the popup panel. Here we are implementing autoCompleteextender to fetch data from the database without using Webservice.

AutoComplete Extender:

AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.

The dropdown with candidate words supplied by a web service is positioned on the bottom left of the text box.

Ajax autocompleteextender with example in asp.net



In this article I will explain what Ajax autocompleteextender with Example in asp.net

AutoComplete Extender:

AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.

The dropdown with candidate words supplied by a web service is positioned on the bottom left of the text box.
Syntax:

<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
            ServicePath="WebService.asmx" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1"
            CompletionInterval="1000" ServiceMethod="GetCityName" OnClientPopulating="ShowProcessImage"
            OnClientPopulated="HideProcessImage">
        </ajax:AutoCompleteExtender>

What is Ajax autocompleteextender, Syntax and Properties?


In this article i will explain what is Ajax autocompleteextender? what is the syntax and properties? 

AutoComplete Extender:

AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.
The dropdown with candidate words supplied by a web service is positioned on the bottom left of the text box.

Syntax:

<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
            ServicePath="WebService.asmx" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1"
            CompletionInterval="1000" ServiceMethod="GetCityName" OnClientPopulating="ShowProcessImage"
            OnClientPopulated="HideProcessImage">
        </ajax:AutoCompleteExtender>


Wednesday, 12 February 2014

How to maintain User Login information in Cookies using C#.net

In this article I will explain how to maintain User Login information in Cookies using C#.net.

I have a login screen. In that screen two textboxes (txtUserName, txtPassword) and one button (btnSubmit).

If the end user entered the username and password and clicked the Submit button, we are maintained the user information in cookies. Check the below code.

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        { 
            objclLogin.UserName = txtUserName.Text;
            objclLogin.Password = txtPassword.Text;
            // Checking if the user is valid or not
            dsLogin = objclLogin.ValidateUser();
            if (dsLogin.Tables[0].Rows.Count > 0)
            {
                if (dsLogin.Tables[0].Rows[0][0].ToString() == "1")
                {
                    string UserDetails;
                    dsUserDetails = objclLogin.GetUserDetails();                    
                    UserDetails = dsUserDetails.Tables[0].Rows[0][0].ToString();                   
                    FormsAuthenticationTicket Ticket;
                    string cookiestr;
                    HttpCookie ck;
                    Ticket = new FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true, UserDetails);
                    cookiestr = FormsAuthentication.Encrypt(Ticket);
                    ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
                    ck.Path = FormsAuthentication.FormsCookiePath;
                    Response.Cookies.Add(ck);
                    Response.Redirect("Home.aspx");

                }
            }
        }
        catch (Exception Ex) { } 
    }


How to clear all Session value and close current window using asp.net

In this article I will explain how to clear all Session value and close current window using asp.net.

Below code is useful for remove all session values and close the current window.

Session.Abandon() method is useful for clearing all session values in the application.

FormsAuthentication.SignOut();
Session.Abandon();


ScriptManager.RegisterClientScriptBlock(…..) is useful for closing the current window.  


ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "self.close();", true);


Total Code :

FormsAuthentication.SignOut();
Session.Abandon();

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Close_Window", "self.close();", true);


Label control inside a grid view based on inline Conditional statement in ASP.NET

In this article I will explain how to write in-line query in GridView design page in ASP.NET

First of all you need identify the Column data type. If the column data type is integer then you need to write below code  

<asp:TemplateField HeaderText="Bill Value" HeaderStyle-CssClass="CenterAlign" ItemStyle-HorizontalAlign="Right">
        <ItemTemplate>
               <asp:Label ID='lblBillValue' runat="Server" Text='<%# (Convert.ToInt32(Eval("Value")) > 0?Eval("Value", "{0:0.00}"):"")%>'></asp:Label>
        </ItemTemplate>

 </asp:TemplateField>