Rabu, 17 Juli 2013

How to use Hyperlink control in ASP.NET

Related Post:
Introduction
The HyperLink control is used to create a link to another Web page that can be a page in your Web application. or anywhere else on the World Wide Web (www) . The HyperLink control exists within the System.Web.UI.WebControls namespace.
You can specify the location of the linked page by specifying its URL on the current page . You can use text as well as an image in the HyperLink control. Text is specified with the Text Property and image is specified by the ImageUrl property . By default , when you click a Hyperlink control , the Hyperlinked content appears in a new browser window. You can set the Target property to the name of a window or frame , as linked in blow

Target property Options of the HyperLink class
_blank : Displays the hyperlinked content in a new window without frames.
_parent : Displays the Hyperlinked content in the immediate frameset parent
_self : Displays the Hyperlinked content in the frame with focus.
_top : Displays the Hyperlinked content in the full window without frames.

Public Properties of the HyperLink Class
ImageUrl : Obtains the path to an image to be displayed for the HyperLink control.
NavigateUrl : Obtains the URL to link to the Web page when the HyperLink control is clicked.
Target : Obtains the target window to display the Web page data when the HyperLink control is clicked.
Text : Obtains the text caption for the HyperLink control 

Example of Hyperlink control in ASP.NET  
 





    <%@ Page Language="C#" %>
    <!DOCTYPE html>
    <script runat="server">
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:HyperLink Target ="_blank" ID="HyperLink1" runat="server" NavigateUrl ="http://www.id-script.com"> Worldbest programming blog on blogspot</asp:HyperLink>
        </div>
        </form>
    </body>
    </html>
    Output 
    How to use hyperlink control in asp.net

    Programming techniques and logic in C

    Related post

    Introduction
    The tools like algorithm and flow charts help in understanding the problem and analyzing it. Once the problem and the required solution format are clear , the programming is too easy . In order to program the logical structure derived from algorithm or flowchart , one of the programming languages is picked . The selection of the programming language also depends on the nature of the problem.
    You will see the different programming techniques that are used to solve a problem. The solution of the problem is nothing but to design the program . Before going into the actual design , one should understand the features, merits and demerits of each programming technique .

    After selecting the technique for programming , the next step is the selection of logic . In general , a program can be written in different ways. The different ways give rise to the logic of the program. One of the programs whose logic is simple and understandable is finally selected for implementation. The logic of the program depends on the capability of the programming language . The capabilities of the programming language include the availability of different types of statements . A good logic selection will also improve the performance and efficiency of the designed program.

    Introduction to programming techniques
    Now , let us see " what are the different types of programming techniques?"
    Definition : A method used to design the program to solve a problem or task is called programming technique. The following content shows the number of techniques available for programming.

    Programming Techniques:
    • Top-down
    • Bottom-up
    • Unstructured
    • Structured
    • Modular

     

    Selasa, 16 Juli 2013

    How to use FileUpload Control in ASP.NET

    Introduction
    The FileUpload control displays a text box control and a browse button that enable users to browse a file from the local or remote machine to upload it on the Web server. You can upload a file on the Web Server by specifying the full path of the file to be uploaded (for example D:\Myfiles\Test.txt) in the textbox of this control . Alternatively , you can select the file by clicking the browse button , and then locating it in the Choose File dialog box.

    Public Properties of the FileUpload Class
    FileBytes : Obtains an array of the bytes in a file that is specified by using a FileUpload control

    FileContent : Obtains a Stream object that points to a file to upload using the FileUpload control.

    FileName : Obtains the name of a file on a client to upload using the FileUpload control.

    HasFile : Obtains a value indicating whether the FileUpload control contains a file.

    PostedFile : Obtains the underlying HttpPostedFile object for a file that is uploaded by using the FileUpload control.

    Public Method of the FileUpload Class
    SaveAs : Saves the data of an uploaded file to a specified path on the web server.

    Example of FileUpload control in ASP.NET


    <%@ Page Language="C#" %>
    <!DOCTYPE html>
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.FileName));
            }
            else
            {
                emptyupload.Text = "Choose your file"; 
            }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            .auto-style1 {
                font-size: larger;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div class="auto-style1">
       
            <strong>Pick Your file from file upload control<br />
            </strong>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Save" />   
            <br />
            <asp:Label ID="emptyupload" runat="server"></asp:Label>   
        </div>
        </form>
    </body>
    </html>
    Output
    Example of file upload control in asp.net
     
    Example of file upload control
     
    Only GIF image support by FileUpload control   
     
     
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {        string extn=string.Empty ;
            if (FileUpload1.HasFile)
            {
                extn = System.IO.Path.GetExtension(FileUpload1.FileName);
                if ("gif" == extn)
                {
                    FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.FileName));
                    emptyupload.Text = "Save sucessfully";
                }
                else
                {
                    emptyupload.Text = "only gif support";
                }
            }
            else
            {
                emptyupload.Text = "Choose your file"; 
            }
        }
    </script>
    Note : GetExtension is the method of the path class which is detect extension of the filename.

    Senin, 15 Juli 2013

    How to use Literal Control in ASP.NET

    Introduction of Literal control in ASP.NET:
    The literal control is another Web Server control used for displaying text on a Web page, similar to that done by a Label control in ASP.NET , You can add HTML in a web page with the help of Literal control , without switching to the .aspx page. The Literal control exists within the System.Web.UI.WebControls namespace.

    Public Properties of the Literal Class

    Mode : Obtains or sets an enumeration value that specifies how the content in the Literal control is rendered.

    Text : Obtains or sets the caption displayed in the Literal control.

    Example of Literal control

    How to use Facebook developer plugin using Literal control.


    <%@ Page Language="C#" %>
    <!DOCTYPE html>
    <script runat="server">
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
       
            <asp:Literal ID="Literal1" runat="server" Mode ="Transform">
                <div id="fb-root"></div>
    <script>(function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=257965964247226";
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
                <div class="fb-like-box" data-href="https://www.facebook.com/Dotprogramming?ref=hl" data-width="292" data-show-faces="true" data-stream="true" data-show-border="true" data-header="true"></div>          
            </asp:Literal>
       
        </div>
        </form>
    </body>
    </html>
    Output
    How to use Literal Control in ASP.NET
     
    When you add a Literal control on a web page , The following code is added to the source code of the Web page.
     
    <asp:Literal Id="Literal1" runat="server"></asp:Literal>
    in above example mode property is set to Transform that convert your HTML tag into your HTML output.
    simply you can say
    <H1> Hello world </H1>
     
    Transform enumeration property  gives effect of the heading Tag
    Output
    Hello world
     
     
     
    

    Minggu, 14 Juli 2013

    Principles of Programming in C

    Introduction to Programming
    Remember your last visit to the super market. You might have purchased many items. What did you do after picking all the items and putting them into the carriage? Probably you met with the billing clerk to make the payment. Have you observed his way of preparing the bill? He picks the items one by one and enters something into the computer repeating the same task for all the items.
    Within a count of few minutes or even may be within few seconds he gives the bill , you pay and come out carrying all the required things. So what made him to process the bill so fast? It is nothing but the “program” running in the computer’s memory. If you want to become a billing clerk, then what is needed is to just learn the method to use the program that helps in the billing the items.
    Stop, don’t think in that way. You should dream something high! To design a program that helps the billing clerks to prepare the bill fast and in a most efficient way.

    Program Concept
    By and large computers are used either to run the designed programs or to design the program itself. As an upcoming programmer you are going to use the computer to design the programs. That should be your main dream and aim. Keeping that in mind, let us see “what is program?”
    Definition:  A program, strictly, a computer program is a collection of coded instructions to direct a computer to perform a desired set of operations. So, coding the instructions to make a program is an art. This art of making or designing a program is called programming. The person who writes such programs is called programmer.

    Another definition of program:

    Algorithm + Data Structure = Program

    Definition : A program can be defined as the combination or clubbing of algorithm and data structure together into single unit. Here the algorithm refers to the procedure containing primitive steps to solve a particular task. A primitive step implies an easily understandable one. Data structure refer to the modeling of the required data to solve the task.

    A programmer can design the program as per the customer's needs. The customer's need is collected as problem . The problem is analyzed to arrived at a solution. This solution provided using certain tools is called program. Whenever a problem arises , the programmer can design a program. The designed program can also be used to solve some related problems with the little modification. Changes is the nature! The new demands, requirements , etc. rise as the time passes. The programmer should react properly to these and should come out with a new solution from the existing solutions. Such existing solutions along with the new solution frame a program library. Now, let us see " what is program library?"

    Definition: A library , a store or collection of computer programs is called program library . Each and every program in the library is designed to solve a certain type of problem.

    What is canned program?

    Definition : A program in a library of computer programs is called canned program. Existence of libraries of program that are easy to use and designed to solve very general problem is important .

     

    Sabtu, 13 Juli 2013

    Online Examination System Project in ASP.NET

    Introduction:
    You can conduct your examination online using online Examination system project. Basically this project is designed for helping conductor. This application is designed for college level project its not used for education purpose.

    Login Control


    This module provide interface with admin login also provide security to your project. Your admin can see your result or update your questions.

    

    


    <%@ Page Language="C#" Theme="all" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Data" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            // check whether credentials are valid
            SqlConnection con = new SqlConnection(DBUtil.ConnectionString );
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from oe_members where lname = @lname and pwd = @pwd",con);
                cmd.Parameters.Add("@lname", SqlDbType.VarChar, 10).Value = txtLname.Text;
                cmd.Parameters.Add("@pwd", SqlDbType.VarChar, 10).Value = txtPwd.Text;
              
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Session.Add("mid", dr["mid"]);
                    Session.Add("fullname", dr["fullname"]);
                    Session.Add("dlv", dr["dlv"]);
                    // update MEMBERS table for DLV
                    dr.Close();
                    cmd.CommandText = "update oe_members set dlv = getdate() where lname = @lname";
                    cmd.ExecuteNonQuery();
                    Response.Redirect("default.aspx");
                }
                else
                {
                    lblMsg.Text = "Invalid Login!";
                    dr.Close();
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text = "Error --> " + ex.Message;
            }
            finally
            {
                con.Close();
            }
          
        }
        protected void dsLogin_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    <style type="text/css">
     .Hd
     {
         height:100px;
         margin:auto;
         background-color:#DFA;
     }

     .Hd1
     {
         width:1000px;
         height:100px;
         margin:auto;
         border-left:1px solid #ccc;
         border-right:1px solid #ccc;
       
     }

     .Fd
     {
         height:80px;
         margin:auto;
         background-color:#DFA;
     }

     .Fd1
     {
         width:1000px;
         height:80px;
         margin:auto;
         border-left:1px solid #ccc;
         border-right:1px solid #ccc;
       
     }

     .Nd
     {
         height:35px;
         margin:auto;
         background-color:#1AA;
     }

     .Nd1
     {
         width:1000px;
         height:25px;
         margin:auto;
         padding-top:10px;
         border-left:1px solid #ccc;
         border-right:1px solid #ccc;
         font-weight:bold;
        
        
     }


     .Md
     {
         height:500px;
         margin:auto;
         background-color:#ffA;
     }

     .Md1
     {
         width:1000px;
         height:500px;
         margin:auto;
         border-left:1px solid #ccc;
         border-right:1px solid #ccc;
        
        
     }
    </style>
    </head>
    <body>
    <center>
        <form id="form1" runat="server">
        <div class="Hd"><div class="Hd1"> <h2 style=" padding-top:30px;">ONLINE EXAMINATION SYSTEM</h2></div></div>
       
        <div class="Nd"><div class="Nd1"> <a style="color:White; font-family:Trebuchet MS;text-decoration:none;" href="login.aspx">About Us</a>  | <a style="color:White; font-family:Trebuchet MS; text-decoration:none;" href="contact.aspx">Contact Us</a>| <a style="color:White; font-family:Trebuchet MS; text-decoration:none;" href="all/adminLogin.aspx">Admin Module</a> </div></div>
       
        <div class="Md"><div class="Md1">
            <div style="width:400px; height:500px; color:Maroon; text-align:justify; padding:5px; line-height:25px; font-family:Trebuchet MS;  float:left;">
            <h3>About System</h3>
            OnlineExams is being launched because a need for a destination that is beneficial for both
    institutes and students. With this site, institutes can register and host online exams. Students can
    give exams and view their results. This site is an attempt to remove the existing flaws in the
    manual system of conducting exams.
    <br />Purpose
    <br />Online Exams System fulfills the requirements of the institutes to conduct the exams online.
    They do not have to go to any software developer to make a separate site for being able to
    conduct exams online. They just have to register on the site and enter the exam details and the
    lists of the students which can appear in the exam.
    Students can give exam without the need of going to any physical destination. They can view
    the result at the same time.
    Thus the purpose of the site is to provide a system that saves the efforts and time of both the
    institutes and the students.</div>
            <div style="width:500px; height:500px;  float:right;">
            <br />
            <br />
            <h4>Login</h4>
            <br />
            <table >
                <tr>
                    <td>Login Name :</td>
                    <td><asp:TextBox ID="txtLname" runat="server" Width="150px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtLname" ErrorMessage="Llogin name is missing!" Font-Bold="True">*</asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td>Password :</td>
                    <td><asp:TextBox ID="txtPwd" runat="server" TextMode="Password" Width="150px"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPwd" ErrorMessage="Password is missing!" Font-Bold="True">*</asp:RequiredFieldValidator></td>
                </tr>
               <tr>
              <td colspan="2">
                  <asp:CheckBox ID="chkRemember" runat="server" Text="Remember Me" /></td>
               </tr>
            </table>
            <br />
            <asp:Button ID="btnLogin" runat="server" Text="Login" Width="116px" OnClick="btnLogin_Click" /><br />
            <br />
            <asp:Label ID="lblMsg" runat="server"></asp:Label>
            <p>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please correct the following errors:" Font-Bold="True" />
            <p/>
            <a href="all/newuser.aspx">New User?</a>
            &nbsp; &nbsp;
            <a href="all/forgotpassword.aspx">Forgot Password?</a> 
         
            <asp:SqlDataSource ID="dsLogin" runat="server" ConnectionString="<%$ ConnectionStrings:examConnectionString %>"
                SelectCommand="select * from members where  lname = @lname and pwd = @pwd"
                    onselecting="dsLogin_Selecting">
                <SelectParameters>
                    <asp:Parameter Name="lname" />
                    <asp:Parameter Name="pwd" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div></div>
        </div>
        <div class="Fd"><div class="Fd1"> <p style="color:Blue; font-family:Trebuchet MS; padding-top:20px; font-weight:bold;">Developed  By: Uma Siyota, Hariom, Babu Lal, Deepak Godara</div></div>
       
        </form>
    </center>   
    </body>
    </html>
    Project requirements
    • Visual studio 2010
    • Sql server 2008




    Your project will submit after 5 hour 

    Jumat, 12 Juli 2013

    How to use BulletedList Control in ASP.NET

    Introduction
    The BulletedList control is a standard web server control used to display items in the form of a bulleted list on a web page.
    This control has no non-inherited methods. The BulletedList inherits the ListControl class.
    Public Properties of the BulletedList class
    AutoPostBack : Obtains or sets the value of the AutoPostBack property of the control for the base class
    BulletImageUrl : Obtains or sets the path to an image to display each bullet in a control.
    BulletStyle : Obtains or sets the style of the bullets for the BulletedList control.
    Controls : Obtains a ControlCollection collection for the control.
    DisplayMode : Obtains or sets the display mode of the list items appearing in a BulletedList control.
    FirstBulletNumber : Obtains or sets the value that starts the numbering of list items in an ordered BulletedList control
    SelectedIndex: Obtains or sets the zero based index of the currently selected item in a bulletedList control.
    SelectedItem : Obtains the currently selected item in a BulletedList control.
    SelectedValue : Obtains or sets the value property of the selected ListItem object in the BulletedList control.
    Target : Obtains or sets the target window to display the data of the Web page that is linked to when a hyperlink in a bulletedList control is clicked.
    Text : Obtains or sets the text for the BulletedList control.

    Public event of the BulletedList class
    Click : Occurs when a link button in a BulletedList control is clicked.

    To specify the bullet type to display the list item in a bulleted list control. you can set the BulletStyle property to one of the bullet types that are defined by the BulletStyle enumeration.

    Bullet style of the BulletedList Control
    NotSet : Represents an unspecified bulleted list style the browser automatically sets the style of the bulleted list.
    Numbered : Represents the bullets in the form of numbers.
    LowerAlpha : Represents the bullets in the form of lowercase letters.
    UpperAlpha : Represents the bullets in the form of uppercase letters.
    LowerRoman : Represents the bullets in the form of lowercase Roman numerals.
    UpperRoman : Represents the bullets in the form of uppercase Roman numerals.
    Disc : Represents the bullets in the form of a filled circle.
    Circle : Represents the bullets in the form of a empty circle.
    Square : Represents the bullets in the form of a filled square.
    CustomImage : Represents the bullets in the form of a custom image.

    Example of BulletedList Control

    Database table
    bulletdatabase

    Code
    <%@ Page Language="C#" %>
    <!DOCTYPE html>
    <script runat="server">
        protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
        {
            if (e.Index ==0)
            {
                Image1.ImageUrl = "~/images/heroAccent.png";           
               
            }
            if (e.Index ==1)
            {
                Image1.ImageUrl = "~/images/orderedList0.png"; 
            }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>   
            <br />
            Click the name to see the user&#39;s photo<asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="username" DataValueField="Id" DisplayMode="LinkButton" OnClick="BulletedList1_Click">
            </asp:BulletedList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [usertable]"></asp:SqlDataSource>   
        </div>
            <asp:Image ID="Image1" runat="server" Height="110px" Width="110px" />
            <br />
        </form>
    </body>
    </html>
    Output

    bulleted list
    Related article