Sunday, March 11, 2012

500 error when using a TextBox instead of a label?

The first thing to do is find out what the 500 error tells you. If you already have access to the details of the error, post it here together with the line of code that causes it. If you are getting a Page Cannot Be Displayed error message then, in IE, go to Tool -> Internet Options -> Advanced, then uncheck Show friendly http errors.


Hi,

Sound strange!

Everyone knows textbox works with AJAX. Would you please post up your code?

Best Regards,


Here is the error I get:

Sys.WebForms.PageRequestManagerServerErrorException:An unknown error occurred while processing the request on the server. Thestatus code returned by the server was: 500

It keeps popping up continuously. OnTicker I guess. If I change to Label control then it works just fine.

Here is my code, it's a very simple test:

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyAjaxSampleApp._Default" %><!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>Page Updater</title></head><body> <form id="form1" runat="server"> <br /> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick"> </asp:Timer>      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ContentTemplate> </asp:UpdatePanel> <div>  </div> </form></body></html>
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.IO;namespace MyAjaxSampleApp{public partialclass _Default: System.Web.UI.Page {string aStr ="Lorem ipsum amet dolor. ";string aFile ="Content.txt";protected void Page_Load(object sender, EventArgs e) { }protected void Timer1_Tick(object sender, EventArgs e) {using(StreamWriter aWriter = File.AppendText(aFile)) { aWriter.WriteLine(aStr + Util.Counter.ToString()); aWriter.Close(); }using(StreamReader aReader =new StreamReader(aFile)) { TextBox1.Text = aReader.ReadToEnd(); aReader.Close(); } Util.Counter++; } }}

But this works on my machine:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="MyAjaxSampleApp._Default" %>
<!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 id="Head1" runat="server">
<title>Page Updater</title>
</head>
<body>
<form id="form1" runat="server">
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">
</asp:Timer>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<div>
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;


namespace MyAjaxSampleApp
{
public partial class _Default : System.Web.UI.Page
{
private string aStr = "Lorem ipsum amet dolor. ";
private string aFile = "C:/Content.txt";
private static int Counter = 0;

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Timer1_Tick(object sender, EventArgs e)
{
using (StreamWriter aWriter = File.AppendText(aFile))
{
aWriter.WriteLine(aStr + Counter.ToString());
aWriter.Close();
}

using (StreamReader aReader = new StreamReader(aFile))
{
TextBox1.Text = aReader.ReadToEnd();
aReader.Close();
}

Counter++;

}
}
}

Is youraFile lack of write-power?

No comments:

Post a Comment