Friday, 28 March 2014

find control Id from all data control in asp.net


previous page will not back after log-out

--> When you logged out successfully and click on browser's back button then it should not be come back again in your home page.
--> It means previous page will not back after log-out
--> The following code is for previous page will not back after log-out

Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

It's solution for

 

Browser Back Button Issue After Logout
Back Button issue after Logout in ASP.NET
Avoid go back after Logout
prevent go back after logout


Following code is use in Page_Load() method of your Home page or Master page.


public void RemoveCache()
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();
    }

Log-out code in asp.net with C#

The following code is for log out

Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

Use following code for log out and redirect in log-in page.


public void LogOutCode()
    {
        Session.Abandon();
        Session.Clear();
        Session.Remove("SessioName");

        Response.Redirect("~/Log-in.aspx");
    }

fill data from database using javascript code without page refresh


css file change runtime in asp.net


file update or delete in asp.net

--> The following code is for delete file using C# code.
--> If you want to delete file using Asp.net then use following code on your code behind file


Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

Your .aspx file should be like this


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="lblStatus" runat="server" />
            <br />
           <asp:Button Text="Delete File" ID="btnDeleteFile" runat="server" OnClick="btnDeleteFile_Click" />
        </div>
    </form>
</body>
</html>


And your code behind file should be like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDeleteFile_Click(object sender, EventArgs e)
    {
        string FileName = "here-my-file-name";
        string YourPath = Server.MapPath("FolderName") + "\\" + FileName;
        FileInfo GetMyFile = new FileInfo(YourPath);
        if (GetMyFile.Exists)
        {
            GetMyFile.Delete();
            lblStatus.Text = "File is Deleted";
        }
        else
        {
            lblStatus.Text = "File is not Delete";
        }
    }
}

Thursday, 20 February 2014

create database from script file

--> some time required when new user register on particular website that time
     create new database automatically  from script file.

--> script file:  script file is database creation  code you can create script file from your exist database using asp.net with c# code

    how to create script file , the step is following
    -->right click on your database (SQL server 2008 )
    -->select script database as
    -->select create and file to
    -->and open save as dialogue box set name and path where you want save this script file
    -->and click save
    -->then some process is done and  create script file in your download folder or where you set the path when open dialogue box

-->and you must be changes path in script file (open script file and remove or change the local computer path) other-wise your code  gives error

--> add following code in your code behind file

    -->required following namespace
------------------------------------------------------------------------------------------------
    using Microsoft.SqlServer.Management.Smo;
    using Microsoft.SqlServer.Management.Common;

    -->and create following function
------------------------------------------------------------------------------------------------
    public void CreateDatabaseFromScriptfile()
    {
     cn4 = new SqlConnection(@"Data Source=path\SQLEXPRESS,53286;Initial Catalog=databasename;User ID=sa;Password=pwd;");    //Connecrtion string
           string strdbname = "db_" + txtAccountName.Text; //this is for new databsase name
           FileInfo file = new FileInfo(Server.MapPath("Database_Code") + "\\" + "scriptFile.sql");
           //Here  path where your script file is store
           string strscript = file.OpenText().ReadToEnd();
           // in strscript string variable assign script code for replace the database name and execute server side
           string strupdatescript = strscript.Replace("[OldDatabaseName]", strdbname);
           // OldDatabaseName which is you set : when you create script file from which database , set this database name
           Server server = new Server(new ServerConnection(cn4));
           server.ConnectionContext.ExecuteNonQuery(strupdatescript);
          //this executed on server side and create new database , and this database name is value of strdbname

    }

--> above function take some more time for create new database on server side

--> and this function use on click event or any where which you want to

Calculate marksheet using JavaScript

--> Copy following code in your notepad file and save file name with .html
------------------------------------------------------------------------------------------------

<html>
    <head>
        <title>mark-sheet</title>
    <script >
    var s1,s2,s3,s4,s5,s6,s7,total,per,name,roll;
    roll=prompt("enter the student roll no");
    name=prompt("Enter the student name");
    s1=parseInt(prompt("enter subject1 mark    : " ));
    s2=parseInt(prompt("enter subject2 mark    : " ));
    s3=parseInt(prompt("enter subject3 mark    : " ));
    s4=parseInt(prompt("enter subject4 mark    : " ));
    s5=parseInt(prompt("enter subject5 mark    : " ));
    s6=parseInt(prompt("enter subject6 mark    : " ));
    s7=parseInt(prompt("enter subject7 mark    : " ));

    total=s1+s2+s3+s4+s5+s6+s7;
    per=total/7;

    document.write(" <h1>    <center>   MARKSHEET    </h1> </center>");
    document.write(" <hr color=red>   <hr color=red>  ");
    document.write("  <h3>Roll no          :  " + roll);
    document.write(" <br> Name          :  " + name  +"</h3>");
    document.write(" <hr color=black>");
       document.write(" <b> <br> &nbsp &nbsp &nbsp     Subject           &nbsp &nbsp&nbsp &nbsp Mark  </b>");

    document.write(" <br> &nbsp &nbsp &nbsp     Subject 1      &nbsp &nbsp&nbsp &nbsp     &nbsp &nbsp   " + s1);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 2        &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   "  + s2);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 3      &nbsp &nbsp&nbsp &nbsp    &nbsp &nbsp   " + s3);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 4       &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp    " + s4);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 5       &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   " + s5);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 6        &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   " + s6);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 7        &nbsp &nbsp&nbsp &nbsp  &nbsp &nbsp    " + s7);
    if(s1<40 || s2<40 || s3<40 || s4<40 || s5<40 || s6<40 || s7<40)
    {
        document.write(" <hr color=black>");
        document.write("  Total               <b>:  " + total  +  "<br>");   
        document.write(" &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <font color=red  > <h3>Fail  </h3></font>");
    }
    else
    {
        document.write(" <hr color=black>");
        document.write("    Total               :  " + total);   
        document.write("   <br>  Percentage   :  " + per);   
        document.write("   <br> grade                      :");

        if(per>=70)
        {
            document.write("      <b>Districation");
        }
        else if(per >=60)
        {
            document.write("       <b>First class");
        }
        else if(per>=48)
        {
            document.write("       <b>Second class");
        }
        else
        {
            document.write("        <b>pass class");
        }            
    }
    document.write(" <hr color=red>   <hr color=red>  ");
    </script>
    </head>
        <body bgcolor=silver>
    </body>   </html>

--> then open this page in browser

background change when mouseover on button

-->Following code copy in your notepad and save file name with extension .html
------------------------------------------------------------------------------------------------

<html>
    <head>
        <title>Hitesh Kaklotar</title>
    <script>

        function red()
        {
            document.bgColor="red";
        }
        function g()
        {
            document.bgColor="green";
        }

        function b()
        {
            document.bgColor="blue";
        }

        function red()
        {
            document.bgColor="red";
        }

        function s()
        {
            document.bgColor="silver";
        }

        function y()
        {
            document.bgColor="yellow";
        }

        function m()
        {
            document.bgColor="maroon";
        }

        function p()
        {
            document.bgColor="pink";
        }
        function bl()
        {
            document.bgColor="black";
        }
        function w()
        {
            document.bgColor="white";
        }

    </script>
    <style type="text/css">
        .box
        {
            width:700px;
            padding:5px;
            border:5px solid black;
            margin:10px;
            background-color:white;

        }
        body
        {
            //background-color:silver;
            align:right;
            font-style:bold;
        }
        h3
        {
            background-color:silver;
            font-family:arial;
            text-align:right;   
            width:700px;       
            font-size:15px;   
        }
        a:hover
        {
            color:maroon;
            background-color:gray;
            font-family:verdana;
            color:blue;
        }
        #red:hover
        {
            background:red;
        }
        #g:hover
        {
            background:green;
        }
        #b:hover
        {
            background:blue;
        }
        #s:hover
        {
            background:silver;
        }
        #y:hover
        {
            background:yellow;
        }
        #m:hover
        {
            background:maroon;
        }
        #p:hover
        {
            background:pink;
        }
        #bl:hover
        {
            background:black;
        }
        #w:hover
        {
            background:white;
        }
    </style>
    </head>
    <body>
        <br><br>
        <div class="box">

        <h3>
        <a href=" ">Home</a> &nbsp &nbsp
        <a href=" ">Services</a> &nbsp &nbsp
        <a href=" ">About US</a> &nbsp &nbsp
        <a href=" ">Contact US</a> &nbsp &nbsp
        </h3>
        </div>

        <br>
        <input type="button" value="                 RED                          " id="red" OnmouseOver="red()" ><br><br>
        <input type="button" value="                 GREEN                     " id="g"   OnmouseOver="g()"><br><br>
        <input type="button" value="                 BLUE                        " id="b"   OnmouseOver="b()"><br><br>
        <input type="button" value="                 SILVER                     " id="s"  OnmouseOver="s()" ><br><br>
        <input type="button" value="                 YELLOW                  "id="y"   OnmouseOver="y()" ><br><br>
        <input type="button" value="                 MAROON                 " id="m" OnmouseOver="m()" ><br><br>
        <input type="button" value="                 PINK                         " id="p"  OnmouseOver="p()" ><br><br>
        <input type="button" value="                 BLACK                     " id="bl"  Onclick="bl()"><br><br>
        <input type="button" value="                 WHITE                     " id="w"  Onclick="w()" ><br><br>
        <br>       
    </body>
</html>

--> then open this page in your browser , and move mouse pointer on button then display effect
(change background)

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------

Javascript complete validation form  : http://problemaspdotnet.blogspot.in/2014/02/javascript-basic-validation.html

Update progress example in asp.net

--> Page not refresh every time when get new data or fill data in datacontrol

-->if you want to create update progress in your web page for page is not refresh
after some event occurred like Click, CheckedChanged,SelectedIndexChanged.........
   
--> Then do following

---> following code add in your  source(.aspx file)
------------------------------------------------------------------------------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:Button ID="btnSearch" runat="server" Text="Search"> </asp:Button>
<br>
<asp:UpdateProgress ID="updateProgress1" runat="server">
<ProgressTemplate>
 <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0;
 right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
<asp:Image ID="imgUpdateProgress" runat="server"
 ImageUrl="~/your ProgressBar image path/ProgressBar.gif"
 AlternateText="Filling Data ..." ToolTip="Filling Data ..." Style="padding: 10px; position: fixed;
 top: 35%; left: 45%;" />
</div>
</ProgressTemplate>
                </asp:UpdateProgress>
                <asp:UpdatePanel ID="up1" runat="server">
                    <Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
// In ControlID set your control's name     You can use more than one control event here  like following
<%--<asp:AsyncPostBackTrigger ControlID="ddlData" EventName="SelectedIndexChanged" />--%>
  <%--<asp:AsyncPostBackTrigger ControlID="rb3" EventName="CheckedChanged" />--%>
                    </Triggers>
                    <ContentTemplate>
    <asp:gridview ID=gvData runat="server"></asp:Gridview>
    //    Your Data control like Gridview ,ListView .......
    //    Or Table
   
     </ContentTemplate>
                </asp:UpdatePanel>


Asp.net tutorials