calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Feb 15, 2005 6:58 pm Post subject: How to prevent the user from editing the date field directly? |
|
|
Just set your <input> tag as following:
Code: | <input name="dateFieldxxx" value="" readonly="true" onfocus="this.blur()" > |
Note:
For the new ASP.NET 2.0, there is a subtle change to its readonly behavior when EnableViewState is set to false on the Page - the ReadOnly value will no longer post back in ASP.NET 2.0 - the value gets lost. e.g.
Code: | <%@ Page language="c#" enableviewstate="false" Trace="true" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Textbox1.Text = "readonly text";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.lblMessage.Text = this.Textbox1.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body>
<form runat="server" id="Form1">
<asp:textbox ID="Textbox1" runat="server" ReadOnly="true" ForeColor="silver"></asp:textbox>
<asp:textbox ID="Textbox2" runat="server" ReadOnly="true">Some Text</asp:textbox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html> |
This difference between ASP.NET 1.1 and 2.0 can be worked around by using
Code: | this.TextBox1.Text = Request[this.TextBox1.UniqueID]; | in the Page_Load().
Details can be found here: http://west-wind.com/weblog/posts/3939.aspx
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|