Saturday, 29 September 2012

FIle upload in ASP .NET


3. File upload:
















Code for upload button:

 protected void Btnupload_Click(object sender, EventArgs e)
    {
        int sizelimit = 5242880;
        if (FileUpload1.HasFile)
        {
            if (FileUpload1.PostedFile.ContentLength <= sizelimit)
            {
                string path = "c:\\upload\\" + FileUpload1.FileName;
                FileUpload1.SaveAs(path);
                Label1.Text = "file uploaded to " + path;
            }
            else
                Label1.Text = "file exceeds size limit.";
        }
    }

AJAX UPDATE PANEL


2. AJAX UPDATE PANEL







<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 Button1_Click(object sender, EventArgs e)
        {

        }
</script>

    <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
        <asp:Button Text="update" ID="btn_update" runat="server" />
        <%=DateTime.Now.ToString() %>
        </ContentTemplate>
        </asp:UpdatePanel>

    
    </div>
    </form>

</body>
</html>

Tuesday, 18 September 2012

ASP .NET


1.To save data from text box to database:




Naming: 
1. Textbox for name: txtname
2.Textbox for city: txtcity
3. Button for submit: btnsubmit
4.Button for clear: btnclear


In the namespace you must use the following namespace for database connectivity.

using System.Data.SqlClient;

Code for submit button:      


string str = "Data Source=DESAI-PC\\SQLEXPRESS;Initial Catalog=new1;Integrated Security=True";
 SqlConnection con = new SqlConnection(str);
 con.Open();
string sql = "insert into text2db values('" + txtname.Text + "','" + txtcity.Text + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();


Code for clear button: 

txtname.Text = "";
txtcity.Text = "";