Thursday, January 20, 2011

Login page in asp.net

create table as follows

username   password role     status    
adminadmin   adminTrue
svenusvenustockTrue
pvenupvenupurchaseTrue
venuvenuadminTrue





create procedure as

alter proc sp_login(@uname varchar(50),@psw varchar(50))
as
select * from logintable where username=@uname and password=@psw and status=1

 --------------
exec sp_login 'venu','venu'

add a sqlhelperclass as vineetlabs and

create a class file with name as login.cs

using System.Data.SqlClient;
using vineetlabs;
public class login
{
    connection obj = new connection();
    public SqlDataReader login1(string un,string psw)
    {
        SqlParameter[] param = new SqlParameter[2];
        param[0] = new SqlParameter("@uname",un);
        param[1] = new SqlParameter("@psw",psw);
        obj.dr = SqlHelper.ExecuteReader(obj.con,CommandType.StoredProcedure,"sp_login",param);
        return obj.dr;
         obj.dr.Read();
}


next go to bushiness logic that is login.aspx.cs

protected void btn_login_Click1(object sender, EventArgs e)
    {
        SqlDataReader dr = obj1.login1(txt_uname.Text, txt_psw.Text);
        if (dr.Read())
        {
            if (dr[2].ToString() == "sales")
            {
                Response.Redirect("~/SalesManagement/SalesHome.aspx");
            }
            else if(dr[2].ToString()=="purchase")
            {
                Response.Redirect("~/PurchaseManagement/purchaseOrder.aspx");
            }
            else if (dr[2].ToString() == "admin")
            {
                Response.Redirect("~/Administrator/adminhome.aspx");
            }
            else if (dr[2].ToString() == "stock")
            {
                Response.Redirect("~/Inventory/InventoryHome.aspx");
            }
            else
            {
               lbl.Text = "<script>"+Environment.NewLine+"window.alert('Invalid User')</script>";
               Page.Controls.Add(lbl);
               
            }
        }








Wednesday, January 19, 2011

chage to Mixed mode Authentication in sql server 2005

To change security authentication mode

  1. In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
  2. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
  3. In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.

To restart SQL Server from SQL Server Management Studio

  • In Object Explorer, right-click your server, and then click Restart. If SQL Server Agent is running, it must also be restarted.

To enable the sa login by using Transact-SQL

  • Execute the following statements to enable the sa password and assign a password.
    ALTER LOGIN sa ENABLE ;
    GO
    ALTER LOGIN sa WITH PASSWORD = '<enterStrongPasswordHere>' ;
    GO
    

To enable the sa login by using Management Studio

  1. In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties.
  2. On the General page, you might have to create and confirm a password for the sa login.
  3. On the Status page, in the Login section, click Enabled, and then click OK.

    Example:
alter login sa enable
alter login sa with password='asp'

Thursday, January 6, 2011

Adding Row Number to SQL SELECT result

 Query:

select  row_number() over(order by mrnno) from MRNselfMaterialDetails

here
 row_number()-------------is Built in function
over(order by mrnno)-------------is a function 
order by------------------------------key word
mrnno---------------------------------Column Name
MRNselfMaterialDetails-----------Table Name


For More References watch


2) http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=103432

Wednesday, January 5, 2011

POpUp Window

<script type="text/javascript">
function OpenPopup() {
    window.open("popup.aspx","List","scrollbars=no,resizable=no,width=400,height=280");
    return false;
}
</script>

for link button :

OnClientClick="window.open('http://localhost/inventory/warehouse Stock/viewstocks.aspx',  'popup' ,'height=955,width=910,top=150,left=150,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,copyhistory=false');"

http://www.velocityreviews.com/forums/t294803-calling-pop-up-window.html 
http://www.eggheadcafe.com/community/aspnet/7/10066984/aspnet-20-menu-control-opening-a-popup-window-withouth-menubar-etc.aspx
http://www.eggheadcafe.com/software/aspnet/35564887/opening-another-window.aspx


http://www.astahost.com/info.php/Create-Popup-Window-Javascript_t169.html

http://www.eggheadcafe.com/community/aspnet/7/10066984/aspnet-20-menu-control-opening-a-popup-window-withouth-menubar-etc.aspx

Using Ajax ModelPoupExtender:
====================

1) Assign a BehaviourID to the ModalPopupExtender using the BehaviourID attribute.
BehaviorID ="ModalBehaviour"
2) Use the $find method to get a handle to the Modal Popup Behaviour .
$find ("ModalBehaviour").
3) Call your hide and show methods on the acquired handle.
4) The Javascript would look like this.

<script language="javascript"> 

function ShowModalPopup() 
{
  $find("ModalBehaviour").show(); 
}

function HideModalPopup() 
{
 $find("ModalBehaviour").hide(); 
}

</script> 

http://blogs.msdn.com/b/phaniraj/archive/2007/02/20/show-and-hide-modalpopupextender-from-javascript.aspx

Forms Authentication

form authenication code
in web.config
----------------------------
 <authentication mode="Forms">
      <forms loginUrl="Login.aspx">
        <credentials passwordFormat="Clear">
          <user name="vineet" password="vineet123"/>
          <user name="venu" password="venu"/>
          <user name="satheesh" password="satheesh"/>
        </credentials>
      </forms>
     
    </authentication>
    <authorization>
      <deny users="?"/>
     
    </authorization>

in login.aspx
-----------------
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Windows.Forms;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void btn_login_Click(object sender, EventArgs e)
    {
        if (FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text) == true)
        {
            FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
            Response.Redirect("~/Inventory/InventoryHome.aspx");
        }
        else
        {
          MessageBox("INVALID");
        }
       
    }
   
protected void MessageBox(string msg)
{
lbl.Text = "<script language='javascript')>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
Page.Controls.Add(lbl);
}
}




in web.config Write as
===============
<system.web>
<authentication mode="Forms">
<forms loginUrl="UI/login.aspx"
defaultUrl="UI/DashBoard.aspx"
name="abc"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>

In login.aspx Source Html Write as
========================
<asp:TextBox ID="txt_UserName" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_Password" runat="server"></asp:TextBox>

<asp:Button ID="btn_login" runat="server" onclick="btn_login_Click"
Text="Login" />

in login.aspx.cs code behind Write as

=========================
protected void btn_login_Click(object sender, EventArgs e)
{
Session["UID"] = txt_UserID.Text;
int i=Convert.ToInt32(sc.User_Login(txt_UserName.Text, txt_Password.Text));
if (i < 1)
{
alertBox("Invalid User....");
}
else
{

FormsAuthentication.RedirectFromLoginPage(txt_UserName.Text, false);
FormsAuthentication.SetAuthCookie("txt_UserName.Text",false);

}
}



public void alertBox(string msg)
{
Label1.Text = "<script type='text/javascript'>"+Environment.NewLine+"window.alert('"+msg+"')</script>";
Page.Controls.Add(Label1);
}


and in default2.aspx page write in Logout Button click as
========================================================
protected void lnkbtn_LogOut_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect(Request.Path);
}



1) write this query in at the end in submit button
Response.Write("<script language=javascript>alert('you have successfully posted your query');</script>");

2)code Behind page of Controls
Alert.Show("You do not have write permission to this file");

3)property of control write as....
OnclientClick=alert('submitted successfully..');

4)MOre
1)Response.Write("<script language=javascript>window.alert('Enter a valid UserName an Password');</script>");

2)ScriptManager.RegisterClientScriptBlock(this.GetType(), "ClientScript", "window.alert('Vous ne pouvez pas supprimer un client utilisez le
champ Statut');", True);

3)MessageBox.Show("YourMessageHere","YourBoxTitleHere",MessageBoxButtons.YourChoiceOfButtonsHere,MessageBoxIcon.YourChoice
OfIconHere);

4)Response.Redirect("<script>" + "alert('Confirmed');" + "</script>");

5)Response.Write("<script>{window.alert('inserted');}</script>");

6)Response.Write("<script language='javascript' type='text/javascript'>alert('insertedsuccessfully')</script>");

7)Page.ClientScript.RegisterStartupScript(this.GetType(), "OnLoad", "<script language=javascript>ConfirmBoxSave();</script>");

5)
IN PAGE LOAD WRITE AS
1) btn_login.Attributes.Add("onClick", "javascript:history.back(); return false;");

 2) btn_login.Attributes.Add("onclick", "javascript:history.go();return false");//btn_login.Attributes.Add("onClick", "javascript:history.back(); return
false;");

 3)btn_login.Attributes.Add("onclick", "javascript:history.go();return false");

6) Method

protected void MessageBox(string msg)
{
lbl.Text = "<script language='javascript')>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
Page.Controls.Add(lbl);
}
Call this Methos As
MessageBox("Your Message...");

for more Web reference Download  from this link
---------
http://www.ziddu.com/download/13271505/windowalert.rar.html

JQuery Confirm Box..
http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/