Search KB Filter article types
Implementing dialog logon screen
Categories: Forms
Tags: Developers, Windows & Dialogs, C#, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
Revision: 1
Posted: 11/Jan/2007
Updated: 11/Jan/2007
Status: Publish
Types: Code

Visual WebGui provides simple way to implement Logon screen. Adding 'Authentication' element in the web.config file, send the user to the page specified in that element if he/she is not logged on.

<Authentication Mode="Main" Type="Gizmox.WebGUI.Sample.Forms.Logon, Gizmox.WebGUI.Sample" />

Currently the only supported Mode (notice Mode attribute) is Main. In the future we'll also implement Dialog mode.

Jconstantino and rhernandez_64 asked for this feature in this post. Although this feature isn't in our roadmap for the near future, its functionality can be achieved relatively easily. Here are two simple steps you need to take in order to implement a dialog logon screen:

1. Move all the code in the "Form_Load" method of your main form to new method that will be called after the user successfully logged on. Instead if the user is not logged on you should show a dialog popup screen:

Old code:

private void MainForm_Load(object sender, EventArgs e)
      {
            InitializeData();
            Foo();
 
}

New code:

private void MainForm_Load(object sender, EventArgs e)
      {
 
//if user is not logged on - show logon screen
      if (!Context.Session.IsLoggedOn)
 
{
 
                  Logon objLogonPopup = new Logon();
 
objLogonPopup.Closed  = new EventHandler(objLogonPopup_Closed);
objLogonPopup.ShowDialog();
}
 
}
 
private void FormLoad_AfterLogon()
      {
            InitializeData();
            Foo();
            }

2. Create a logon form. And set Context.Session.IsLoggedOn (Boolean) accordingly. If user logged on successfully, then close the form. Else alert the user:

private void btnLogon_Click(object sender, EventArgs e)
      {
            Context.Session.IsLoggedOn = (txtPassword.Text == "pass1" &&
 
txtUsername.Text == "user1");
 
            if (Context.Session.IsLoggedOn)
            {
                this.Close();
            }
            else
            {
                MessageBox.Show(    "Username or Password inocrrect!",
 
"Login Faild",
 
MessageBoxButtons.OK,
 
MessageBoxIcon.Error);
 
}
 
}

You can download the sample application attached...

That's it, enjoy!

Tamir Zaslavsky

Note: Codes are submitted as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Terms of Agreement:
By using this code, you agree to the following terms...

1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3. You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


About the author

Related Articles

Forms  
Title Update Author
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Developers, Theme, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
23/July/2010    2010/07/23
Tags: Developers, Events, Navigation, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
04/Dec/2010    2010/12/04
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04
Tags: Architects, Developers, Navigation, Windows & Dialogs, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
24/May/2010    2010/05/24
Tags: Developers, Events, Windows & Dialogs, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
23/July/2010    2010/07/23
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS