Click here to Skip to main content
15,891,372 members
Articles / Web Development / ASP.NET

Enable ReadOnly Mode for your WebForms!

Rate me:
Please Sign up or sign in to vote.
4.68/5 (20 votes)
24 Feb 2004 70.8K   726   41  
This article will show you, how to implement a readonly mode for webforms.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Trivadis.Spieler.ReadOnly
{
	/// <summary>
	/// Summary description for ReadOnlyDialog.
	/// </summary>
	public class ReadOnlyDialog : BasePage
	{
		protected System.Web.UI.WebControls.DropDownList ddlSex;
		protected System.Web.UI.WebControls.TextBox txtLastname;
		protected System.Web.UI.WebControls.TextBox txtFirstname;
		protected System.Web.UI.WebControls.Label lblCity;
		protected System.Web.UI.WebControls.RadioButtonList optCity;
		protected System.Web.UI.WebControls.Label lblFirstname;
		protected System.Web.UI.WebControls.Label lblLastname;
		protected System.Web.UI.WebControls.Label lblSex;
		protected System.Web.UI.WebControls.Label lblSwiss;
		protected System.Web.UI.WebControls.Label lblFirstnamed;
		protected System.Web.UI.WebControls.Label lblHobby;
		protected System.Web.UI.WebControls.ListBox lstHobbies;
		protected System.Web.UI.WebControls.HyperLink hypGridLayout;
		protected System.Web.UI.WebControls.Button btnSave;
		protected System.Web.UI.WebControls.LinkButton lnkReadOnly;
		protected System.Web.UI.WebControls.LinkButton lnkBack;
		protected System.Web.UI.WebControls.CheckBox chkSwiss;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!this.IsPostBack)
			{
				lnkBack.Attributes.Add("onclick","javascript:history.back(-1);");
				btnSave.Attributes.Add("onclick","javascript:alert('Not implemented now.');");
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.lnkReadOnly.Click += new System.EventHandler(this.lnkReadOnly_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void lnkReadOnly_Click(object sender, System.EventArgs e)
		{
			base.SetReadOnly(this.Controls);
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Switzerland Switzerland
Consultant for Trivadis AG in Switzerland.
Interested in .NET, Architectures, Patterns and Web 2.0.
Blog and articles at http://sharpcuts.blogspot.com

Comments and Discussions