Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGrid where rows can be edited. Inside the EditItemTemplate, one of the columns has a TextBox and a couple of validators. There is data in the textbox.

When I tried to make the textbox read-only, I could still click in the control and get a cursor, and when I hit the baskcspace key (with the caret at the end of the existing text), the app crashes, and at the same time renders bothe the back and forward buttons in the browser completely useless. The only way to recover is to shut the browser down and restart the debugger.

Does anyone know why this might be happening?

NOTES:

0) I tried disabling the validators, and that didn't have any impact on the behavior.

1) If I disable the control, it doesn't crash (and doesn't let me type in the field).

2) I couldn't find anything on google - I'm at a loss.

EDIT =============

The error I get when it crashes is "Web page Expired".
Posted
Updated 2-Aug-11 9:32am
v5
Comments
AspDotNetDev 3-Aug-11 17:19pm    
Have you figured this out? I'm curious what could cause this.
#realJSOP 4-Aug-11 14:55pm    
Not yet... :/

1 solution

I could not reproduce your issue using this code:
ASP.NET
<%@ Page Language="vb" AutoEventWireup="false" %>
<script runat="server">
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim animals As New List(Of Animal)
    animals.Add(New Animal With {.AnimalName = "JSOP"})
    animals.Add(New Animal With {.AnimalName = "Unicorn"})
    dgSample.EditItemIndex = 0
    dgSample.DataSource = animals
    dgSample.DataBind()
  End Sub
  Public Class Animal
    Public Property AnimalName As String
  End Class
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test ReadOnly</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:DataGrid runat="server" ID="dgSample" AutoGenerateColumns="false">
        <Columns>
          <asp:TemplateColumn HeaderText="Animal Name">
            <ItemTemplate>
              Viewing:
              <asp:TextBox runat="server" ReadOnly="true"
                Text='<%# DataBinder.Eval(Container.DataItem, "AnimalName")%>' />
            </ItemTemplate>
            <EditItemTemplate>
              Editing:
              <asp:TextBox runat="server" ReadOnly="true"
                Text='<%# DataBinder.Eval(Container.DataItem, "AnimalName")%>' />
            </EditItemTemplate>
          </asp:TemplateColumn>
        </Columns>
      </asp:DataGrid>
    </div>
    </form>
</body>
</html>


What browser are you using? Perhaps when you click BACKSPACE, you are navigating back to a previous page (that is a common scenario in which you'd get "web page expired")? You can also get "web page expired" when you have done a postback (e.g., after pressing ENTER and activating the default button on the page) and you try to refresh the page. Does the issue occur when you use the DELETE key instead? Could there be some JavaScript that is detecting the BACKSPACE key and causing the browser to navigate to the previous URL? Some other things to check: are you sure ReadOnly is set to "true" in the EditItemTemplate (just to double check) and do you have AutoPostBack set to "true" (that could cause some issues)?
 
Share this answer
 
Comments
#realJSOP 2-Aug-11 17:31pm    
Well, I tried creating a very simple web page with a textbox in it, and set it to read only, and did not experience the problem. It's only the web site I';m actually working on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900