Wednesday, July 31, 2013

How to use ModalPopupExtender Ajax control in Asp.net OR ModalPopupExtender Ajax control Example

Introduction: In this article I will try to explain how we can use the ModalPopupExtender Ajax control in Asp.net.

Description:

We use the ModalPopup control to display the data in popup. Add a new webform to project. Add the below given style between Head Tag:
<style type="text/css">
    #login
    {
    min-width:200px;
    height:110px;
    background-color:#c2e4f0;
    border:1px solid;
    padding:15px 15px;
    border-radius:4px;
      -webkit-box-shadow: 0px 1px 6px rgba(75, 31, 57, 0.8);
-moz-box-shadow:    0px 1px 6px rgba(75, 31, 57, 0.8);
box-shadow:         0px 1px 6px rgba(75, 31, 57, 0.8);
    }
    .modal
    {
    background-color:#333333;
    filter:alpha(opacity=70);
    opacity:0.7;
    }   
    </style>

Monday, July 29, 2013

Control 'grdstudent' of type 'GridView' must be placed inside a form tag with runat=server

Introduction: in this artcile I will explain how to resolve the problem Control 'grdstudent' of type 'GridView' must be placed inside a form tag with runat=server when Export Data from Data controls i.e. Gridview, Datalist etc.
runat server

Description:
In the last article i have explained A page can have only one server-side Form tag.

Error occur when we try to Export the Data from Controls to Pdf, Excel, Word, CSV. To resolve this problem add one function:

public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }


After adding this fuction in code behind the problem has been resolved. It would solve you problem.

A page can have only one server-side Form tag.

Introduction: In this post I have explained how we can solve the problem A page can have only one server-side Form tag.

server-side

Description:
I got this error when I try to export the Gridview web page Data with images to Pdf file. To solve this error add EnableEventValidation = "false" to @Page directive of .aspx page as shown below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportGrdiview_ImagesPDF.aspx.cs" Inherits="ExportGrdiview_ImagesPDF" EnableEventValidation = "false" %>


I hope it will resolve your problem.

Thursday, July 25, 2013

How to Create Login Form in Asp.net OR Login Form with Check Username and Password aviabilty in Asp.net

Introduction: In this post I will explain how we can create Login form with check Username and Password aviability  in Asp.net.
Login Form

Description:
In the last article i have explained How to Create registration form in Asp.net.

After the successfully registration to website, user redirect to login page/form of website. Users enter their username and pasword information to enter in website. If username and password is exis than they will be redirect to welcome page of website otherwise got a message for registration or Invalid user/Password.
To show user login form  Example I created a Table USER_REGISTRATION:
ID
int
USERNAME
varchar(50)
PASSWORD
varchar(50)
FIRST_NAME
varchar(50)
LAST_NAME
varchar(50)
SEX
varchar(50)
EMAIL_ID
varchar(50)

Here ID is autoincrement and primary key.
Take a new website. Add a webform to website. Drag and drop the controls from Toolbox and Design the  .aspx page as shown below:

Wednesday, July 24, 2013

How to Create Registration Form in Asp.net

Introduction: In this article I will explain how we can create simple registration form in Asp.net.
Description:
In the last article I have explained How to check Usernameor Email is exists or not.


Here I create registration form to register new user. In registration form user needs to fill First name, Last name, password, Email, Address etc. Here I validate the registration form using Jquery. See Example:


Friday, July 19, 2013

How to Export Gridview Data to PDF in Asp.net

Introduction: in this article I will explain how we can Export the Gridview Data to PDF in Asp.net
Description:
Data Export feature is unavailable in Asp.net so we use the 3rd party Library. Here we use the iTextSharp DLL and reference. To download iTextSharp DLL Click Here.
Take a new website. Put the downloaded iTextSharp DLL in Bin folder and build the project/website. Add a webform to website and design .aspx page as shown below:

<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To PDF"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      

Wednesday, July 17, 2013

How to use Ajax NumericUpDownExtender control in Asp.net OR Ajax NumericUpDown control Example

Introduction: In this article I will try to explain how e can use the Ajax NumericUpDownExtender control in asp.net.
NumericUpDownExtender

NumericUpDownExtender can be attached to Textbox control to add up and down buttons that increase and decrease the value in Textbox. NumericUpDownExtender properties:
TargetControlID: ID of the Textbox
RefValues:List of the value separated by semicolons(;) to be used for numeric up and down
Width: Combined sixe of Textbox and Up/Down buttons
ServiceDownPath/ServiceUpPath: Path to a web service that returns the data used to get next or previous value.
ServiceDownMethod/ServiceUpMethod: web services method that returns the data to get next and previous value
TargetButtonUpID/TargetButtonUpID: Custom Up/Down buttons

Tuesday, July 16, 2013

How to use Ajax BalloonPopupExtender control in Asp.net OR Ajax BalloonPopupExtender Example

Introduction: In this post I will try to explain how we can use Ajax BalloonPopupExtender in Asp.net.
BalloonPopupExtender

We use the BalloonPopupExtender control to display the popup which contains the content e.g. for help information. BalloonPopupExtender properties:
TargetControlID: ID of the control to attach
BalloonPopupControlID: ID of the control to display
BalloonSize: Optional setting for specify the size of balloon popup i.e. small, medium and large
BalloonStyle: Optional setting specify the theme of balloon popup i.e. Cloud, Rectangle and custom
DisplayOnMouseOver:Optional setting whether to display the balloon popup on the client on MouseOver event or not.

Saturday, July 13, 2013

How to Export Gridview Data to CSV in Asp.net

Introduction: In this article I will explain how we can Export the Gridview Data to CSV in Asp.net
Description:
In last article I have explained How to Bind Gridview in Asp.net.

Take a new website. Add a webform to website and design .aspx page as shown below:
<body>
    <form id="form1" runat="server">
    <div>
     <table>
    <tr><td>&nbsp;</td><td align="right">
        <asp:Button ID="Button1" runat="server" Text="Export To CSV"
            onclick="Button1_Click" /></td></tr>
    <tr><td>&nbsp;</td><td> <asp:GridView ID="grdstudent" runat="server" AutoGenerateColumns="false" DataKeyNames="STUDENT_ID" DataSourceID="SqlDataSource1">
        <Columns>
        <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT NAME" />
        <asp:BoundField DataField="STUDENT_ADDRESS" HeaderText="STUDENT ADDRESS" />
        <asp:BoundField DataField="STUDENT_CLASS" HeaderText="STUDENT CLASS" />
        </Columns>
        </asp:GridView></td></tr>
    </table>
      
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TestBlogConnectionString %>"
            SelectCommand="SELECT * FROM [STUDENT_DETAIL]"></asp:SqlDataSource>
    </div>
    </form>
</body>

Friday, July 12, 2013

How to use Ajax PopupControlExtender in Asp.net OR Ajax PopupControlExtender Example

Introduction: In this article I will try to explain how we can use Ajax PopupControlExtender control in Asp.net.
PopupControlExtender

Description:

Ajax PopupControlExtender control used to open a popup window to display additional information. Popup Control Properties:
TargetControlID: ID of the control to attach to
PopupControlID: ID of the control to display
Position: Optional setting for specify the Popup position i.e. Left, Right, Top, Bottom, Center
CommitProperty: Optional setting specify the control being extend that should be set with the result of the popup

 Add a webform to project. Drag and drop the control from Toolbox. Desgin the .aspx page as shown below:
<asp:ScriptManager ID="ScriptManager2" runat="server">
        </asp:ScriptManager>
        <table><tr><td>Qualification:</td><td><asp:TextBox ID="txtqualification" runat="server"></asp:TextBox></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr><td>Date:</td><td>
            <asp:TextBox ID="txtcalender" runat="server"></asp:TextBox></td></tr>
        </table>      
        <asp:PopupControlExtender ID="PopupControlExtender1" runat="server" TargetControlID="txtqualification"  PopupControlID="panel1"
   Position="Right"
   CommitProperty="value">
        </asp:PopupControlExtender>
        <asp:PopupControlExtender ID="PopupControlExtender2" runat="server" TargetControlID="txtcalender" PopupControlID="pan2" Position="Bottom" CommitProperty="value">
        </asp:PopupControlExtender>      
        <asp:Panel ID="panel1" runat="server">
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
         <asp:RadioButtonList ID="RadioButtonList1" runat="server"
            AutoPostBack="True" BorderColor="#336699" BorderStyle="Solid"
            Width="130px" BorderWidth="1" BackColor="#dadada"
              onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">  

Thursday, July 11, 2013

How to use TabContainer Ajax Control in Asp.net OR TabContainer Ajax Control Example

Introduction: In this article I have try to explain how we can use the TabContainer Ajax control in Asp.net.
TabContainer

Description:

We use the TabContainer Control to show/display the a lot of information on one page. TabContainer contain the set of Tabs. TabPanel define HeaderText and ContentTemplate.
 Add a new webform to project. Drag and drop the TabContainer Control from Toolbox. Design your page as shown below:

    <div style=" width:30%">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:TabContainer ID="TabContainer1" runat="server">
        <asp:TabPanel ID="tab1" runat="server" HeaderText="Employee Detail">
        <ContentTemplate>
        <table align="right"><tr><td><img src="Upload_Images/Thumb/ff9eb48c-e83e-4d55-9d86-6dd405421df3.png" /></td></tr></table>
        <table>
        <tr><td>Employee Name:</td><td>Rakesh</td></tr>
        <tr><td>Address:</td><td>#1219 Sec 40B CHD</td></tr>
        <tr><td>City:</td><td>Chandigarh</td></tr>
        <tr><td>Phone No.:</td><td>1523451245</td></tr>
        </table>
        </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="tab2" runat="server" HeaderText="Employee Qualification">
        <ContentTemplate>
        <table>
        <tr><td>Professional Qualification:</td><td>B.Tech.</td></tr>
        <tr><td>College Name:</td><td>ABCDE</td></tr>
        <tr><td>University:</td><td>ABCD</td></tr>
        <tr><td>Percentage:</td><td>85%</td></tr>
        </table>
        </ContentTemplate>

Wednesday, July 10, 2013

How to handle Custom Error in Asp.net OR Custom Error Handling in Asp.net

Introduction: In this post I will try to explain how we can Handel the error in Asp.net.
Custom Error Handling

Description:
Sometimes in application we would not want to show Error in message i.e. page not found, server is busy etc. when Error generates on application that time application redirect to default error page.
Take a new website and in web.config file write the below mention code:
<configuration>
       <system.web>
              <compilation debug="true" targetFramework="4.0"/>
              <customErrors defaultRedirect="404.aspx" mode="On">
                     <error statusCode="400" redirect="404.aspx"/>
      <error statusCode="500" redirect="505.aspx"/>
              </customErrors>
       </system.web>
</configuration>

400 (4XX) Errors : Client Side
500 (5XX) Errors: Server Side
Note: if any error will comes in application is will redirect the user to 404.aspx.
Add a webform to project. Here I keep its name 404.aspx and design as mention below:
<body style="background-color:#eaeaea;">
    <form id="form1" runat="server">
    <div>
    <table><tr><a href="Default.aspx">Home</a></tr></table>
    <table style="margin-left:380px;margin-top:50px"><tr><td><a href="#"><img src="Images/404.png" /></a></td></tr></table>  
    </div>
    </form>
</body>

Also add another webform for 500 Error (500.aspx) redirect as mention below:
<body style="background-color:#eaeaea;">
    <form id="form1" runat="server">
    <div>
      <div class="css_table_cell">
          <p align="CENTER" class="page_heading">HTTP Error 500 Internal server
            error</p>
          <p><b>Introduction</b></p>
          <blockquote>
            <p>The Web server (running the Web Site) encountered an unexpected
              condition that prevented it from fulfilling the request by the
              client (e.g. your Web browser or our CheckUpDown robot) for access
              to the requested URL.</p>
            <p>This is a 'catch-all' error generated by the Web server.
              Basically something has gone wrong, but the server can not be more
              specific about the error condition in its response to the client.
              In addition to the 500 error notified back to the client, the Web
              server should generate some kind of internal error log which gives
              more details of what went wrong. It is up to the operators of the
              Web server site to locate and analyse these logs. </p>

Tuesday, July 9, 2013

How to Export Datalist Data to Excel document in Asp.net

Introduction: In this post I will explain how we can Export the Datalist Data to Excel Document in Asp.net.
Description:
In the last post I have explained How to Export DatalistData to PDF file in Asp.net, How to Bind Datalist.
 Here I bind the Datalist control using Sqldatasource. See the .aspx desgin below:
<form id="form1" runat="server">
    <div>
    <asp:DataList ID="dlstudent" runat="server" DataKeyField="STUDENT_ID"
            DataSourceID="SqlDataSource1">
            <HeaderStyle Font-Bold="True" BorderColor="Black" />
            <HeaderTemplate>
             <table border="1"><tr style="background-color:Blue;color:White;">
             <td><b>Student Name</b> </td>
             <td>Student Address</td>
             <td>Student Class</td>
             </tr>
            </HeaderTemplate>
            <ItemTemplate>
            <tr style="font-style:italic;">
              <td align="center"><asp:Label ID="lblname" runat="server"
                    Text='<%# Eval("STUDENT_NAME") %>'></asp:Label></td>
                <td align="center"><asp:Label ID="lbladdress" runat="server"
                    Text='<%# Eval("STUDENT_ADDRESS") %>'></asp:Label></td>
               <td align="center"><asp:Label ID="lblclass" runat="server"
                    Text='<%# Eval("STUDENT_CLASS") %>'></asp:Label></td>                  
            </ItemTemplate>          
                       </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TestBlogConnectionString %>"
            SelectCommand="SELECT * FROM [STUDENT_DETAIL]"></asp:SqlDataSource>
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Export To Excel" />
    </div>
    </form>