Search This Blog

Monday, May 30, 2011

Frame in Microsoft Expression Blend 3 Project (silverlight)

I just want to do a very basic thing: to show two different XAML pages, say, Page1.xaml and Page2.xaml in two lateral areas of the MainPage.xaml.
As far as I understood from the manual, the container for the “Page” element is Frame. So, the code in the MainPage.xaml is the following:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" xmlns:local="clr-namespace:TesteFrameWork"
x:Class="TesteFrameWork.MainPage"
Width="640" Height="480">













Unfortunately, the system fails to show the second page Page2.xaml, showing Page1.xaml instead.
Is there any way to walk around this difficulty -- use a container other than Frame or something else???

Wednesday, May 4, 2011

to redirect page to another page code is

Response.Redirect("new.aspx", true);

ASP.Net & C# Login Page

ASP.Net & C# Login Page

Whenever we want to start any project the first thing we think about the User Roles and Login. Generally there will be mainly two User Roles
a) Administrator User
b) Client User

In VS 2005 its very simple to design a Login Page. Because there is no need of bringing textboxes, labels & buttons together to design a login page and writing code in that button click event. The VS 2005 have a readymade tool in its toolbox called as “Login”.
You just have to Drag & Drop that on your .aspx page


After drag & drop you can change that to your desired design by clicking on Auto Format


Then we need to go to the ‘Properties’ of that Login Control and click on Events.
There we can see a event called Authenticate, Double click on it.



Once that is done. You have to write the C# code in that event

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

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

}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
try
{
string uname = Login1.UserName.Trim(); //Get the username from the control
string password = Login1.Password.Trim(); //get the Password from the control
bool flag = AuthenticateUser(uname, password);
if (flag == true)
{
e.Authenticated = true;
Login1.DestinationPageUrl = “After_Login.aspx”;
}
else
e.Authenticated = false;
}
catch (Exception)
{
e.Authenticated = false;
}
}

private bool AuthenticateUser(string uname, string password)
{
bool bflag = false;
string connString = “Server=localhost;Database=mproi;Uid=sa;Pwd=;”;
string strSQL = “select * from tbl_user where user_name =’” + uname + “‘ AND user_password =’” + password + “‘”;
DataSet userDS = new DataSet();
SqlConnection m_conn;
SqlDataAdapter m_dataAdapter;
SqlCommand m_Command;
try
{
m_conn = new SqlConnection(connString);
m_conn.Open();
m_dataAdapter = new SqlDataAdapter(strSQL, m_conn);
m_dataAdapter.Fill(userDS);
m_conn.Close();
}
catch (Exception ex)
{
userDS = null;
}

if (userDS != null)
{
if(userDS.Tables[0].Rows.Count > 0)
bflag = true;
}
return bflag;
}
}


That’s it. Its all Done. Your Login Page is ready. Its So Simple isn’t it!