render blocks fun (easy answer)

  • Thread starter Thread starter lyndon
  • Start date Start date
L

lyndon

This should be an easy answer, but i'm having problems finding the answer.
I have set a session variabel named Session["ynEdit"] that has the value of
True or False;
Session["ynEdit"] = true;
I'm using this value to determine whether or not textboxes should be
readOnly or not. The code i'm using for the textboxes is:
<asp:textbox id="id" runat="server"
ReadOnly='<%=Convert.ToBoolean(Session["ynEdit"])%>'>

I've also used

<asp:textbox id="id" runat="server" ReadOnly='<%Session["ynEdit"]%>'>

I keep getting the same result (see below) Thanks in advance.

Lyndon Hughey

Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: <%=Convert.ToBoolean(Session["ynEdit"])%> is not a
valid value for Boolean.

Source Error:

Line 28: <asp:TableCell>Entity Number</asp:TableCell>
Line 29: <asp:TableCell>
Line 30: <asp:textbox id="Number" runat="server"
ReadOnly='<%=Convert.ToBoolean(Session["ynEdit"])%>'></asp:TextBox></asp:Tab
leCell></asp:TableRow>
Line 31: <asp:TableRow>
Line 32: <asp:TableCell ColumnSpan="2"><hr></asp:TableCell></asp:TableRow>
 
Here's one way:

<%@ Page Language="CS" AutoEventWireup="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>chkreadonly</title>
<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
Session["ynEdit"]=true;
txtbox1.ReadOnly=Convert.ToBoolean(Session["ynEdit"]);
}
</script>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="txtbox1" runat="server"></asp:textbox>
</form>
</body>
</HTML>
 
Thanks Ken.
I solved the problem taking a different approach

public void makeReadOnly()
{
foreach (System.Web.UI.Control c in this.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
((TextBox)c).Attributes.Add("ReadOnly",Convert.ToString(true));
}
}

}

Thanks again,
Lyndon

Ken Cox said:
Here's one way:

<%@ Page Language="CS" AutoEventWireup="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>chkreadonly</title>
<script runat="server" language="C#">
private void Page_Load(object sender, System.EventArgs e)
{
Session["ynEdit"]=true;
txtbox1.ReadOnly=Convert.ToBoolean(Session["ynEdit"]);
}
</script>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="txtbox1" runat="server"></asp:textbox>
</form>
</body>
</HTML>


lyndon said:
This should be an easy answer, but i'm having problems finding the answer.
I have set a session variabel named Session["ynEdit"] that has the value
of
True or False;
Session["ynEdit"] = true;
I'm using this value to determine whether or not textboxes should be
readOnly or not. The code i'm using for the textboxes is:
<asp:textbox id="id" runat="server"
ReadOnly='<%=Convert.ToBoolean(Session["ynEdit"])%>'>

I've also used

<asp:textbox id="id" runat="server" ReadOnly='<%Session["ynEdit"]%>'>

I keep getting the same result (see below) Thanks in advance.

Lyndon Hughey

Parser Error
Description: An error occurred during the parsing of a resource required
to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: <%=Convert.ToBoolean(Session["ynEdit"])%> is not a
valid value for Boolean.

Source Error:

Line 28: <asp:TableCell>Entity Number</asp:TableCell>
Line 29: <asp:TableCell>
Line 30: <asp:textbox id="Number" runat="server"
ReadOnly=' said:
leCell></asp:TableRow>
Line 31: <asp:TableRow>
Line 32: <asp:TableCell
 
Back
Top