Ajax error when using response.write()

J

Jim in Arizona

I'm brand new at ajax. In fact, about 20 minutes ago was the first time I
got it to work. The problem I'm having on another page did not work,
however.

I'm running into the following error:

Sys.WebForms.PageRequestManagerParserErrorException: The message received
from the server could not be parsed. Common causes for this error are when
the response is modified by calls to Response.Write(), response filters,
HttpModules, or server trace is enabled.
Details: Error parsing near 'greengreengreengreen'.


This is my code. The strBorder variables is filled with an RGB color string
from the code behind page, ie, the color Green (as noted in the error
message I guess). I'm basically changing the color of a text box border
based on what is being returned from the database. Its a system status
message so if things are going wrong, a little red stop light is loaded next
to the message and the border around the message changes to red.


<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="15000"
Enabled="true" OnTick="Timer1_Tick" />

<asp:DataList ID="dlSystemStatus" runat="server" RepeatColumns="1"
Width="100%">
<ItemTemplate>

<div style="border-bottom: 4px;
border-left: 4px;
border-right: 4px;
border-top: 4x;
border-bottom-style: double;
border-left-style: double;
border-right-style: double;
border-top-style: double;
border-bottom-color: <%Response.Write(strBorder) %>;
border-left-color: <%Response.Write(strBorder) %>;
border-right-color: <%Response.Write(strBorder) %>;
border-top-color: <%Response.Write(strBorder) %>;
background-color: White;
margin-right: 5%;
padding:5px;
font-family:Tahoma;font-size:10pt;">

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="width:40px;"><img
src="<%Response.Write(strLight)%>" align="absmiddle" /></td>
<td valign="top">
<i>Posted By <%# Eval("originator") %>, <%#Eval("jobdesc")%> on <%#
Eval("date") %> at <%#Eval("time")%></i>
<hr size="2" color="black"/>
<b>Customer Message</b>
<br />
<%# Eval("message") %>
<hr />
<b>Technical Details</b>
<br />
<%#Eval("technical")%>
</td>
</tr>
</table>

</div>

</ItemTemplate>
</asp:DataList>

</ContentTemplate>
</asp:UpdatePanel>

If AJAX can't handel the Response.Write within the update panel, is there
another way to go about this?

TIA,
Jim
 
M

Mark Stevens

<div style="border-bottom: 4px;

Have you thought about using and ASP Panel here and setting the colour
on the server?
<td valign="top" style="width:40px;"><img
src="<%Response.Write(strLight)%>" align="absmiddle" /></td>

Similarly, use an ASP Image control for the image and Labels for the
messages.
If AJAX can't handel the Response.Write within the update panel, is there
another way to go about this?

Regards,
Mark
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".
 
L

Lucid

Not sure if this is the same problem I had a bit ago, but if you have trace
turned on for the page, Ajax goes insane about it.
 
J

Jim in Arizona

Mark Stevens said:
Have you thought about using and ASP Panel here and setting the colour
on the server?


Similarly, use an ASP Image control for the image and Labels for the
messages.


Regards,
Mark
--
|\ _,,,---,,_ A picture used to be worth a
ZZZzzz /,`.-'`' -. ;-;;, thousand words - then along
|,4- ) )-,_. ,\ ( `'-' came television!
'---''(_/--' `-'\_)

Mark Stevens (mark at thepcsite fullstop co fullstop uk)

This message is provided "as is".



I started to do what you suggested but ran into some problems.
I'm not all that good with asp.net so I do run into some frustrations from
time to time.

The problem here is that I'm using a datalist. Any asp:controls that I place
within the <asp:datalist..> element on the aspx page are not recognized when
I try to utilize them in the code behind.

This is a basic datalist object and I am not using any of its 'commands'. In
the past when I had used them, the sub looked like this:

Sub UpdateRequest(ByVal sender As Object, ByVal e As
DataListCommandEventArgs)

The datalistcommandeventargs object allowed me to 'find' the asp item within
the aspx page by doing something like this:

Dim imgSignalLight As New Image
imgSignalLight = e.Item.FindControl("imgSignalLight")

Then I could manipulate the object.

I can't seem to find any other way to fix my current problem. IN my code
behind page, I have a simple sub procedure (method as you C# people like to
call them) that does the database connection and SQL query to fill the
dataset that populates the datalist located on the aspx page. I can't just
at 'e As DataListCommandEventArgs' as a part of the procedure. I tried to
create a DataListCommandEventArgs object within the connection sub routine
but it asked for things I didn't know, ie:

Dim e As DataListCommandEventArgs(item as DataList, commandSource as Object,
originalArgs as CommandEventArgs)

the datalist would be the name of my datalist, I'm assuming, but I can't
figure out what the other objects would be or where they would come from.

So, the point is, is that I can't use any asp.net controls within a datalist
UNLESS they are part of the datalist's standard events, like UpdateCommand,
DeleteCommand, and so on, where I could then reference the objects using the
DataListCommandEventArgs class stated as a paramater within one of these
'Command' events. All I need to do is figure out how to make my own
procedure (method) that works like the Command events that are part of the
datalist control. I actually tried that but then I don't know how to call
the procedure properly, ie:
Sub SystemStatus()
db connection code here
End Sub

into

Sub SystemStatus(ByVal sender As Object, ByVal e As
DataListCommandEventArgs)
....db connection and query code...
Dim imgSignal as Image
imgSignal = e.Item.FindControl("imgSignal")
End Sub

Then, how would I call that sub, say, within the Page_Load routine (or ajax
timer routine)? What would be the 'sender' object that would be a required
paramater, for instance?
 
J

Jim in Arizona

Lucid said:
Not sure if this is the same problem I had a bit ago, but if you have
trace turned on for the page, Ajax goes insane about it.


Well, its worth a try rather than trying to redo all my code.
Is tracing turned on by default because I didn't take any action to turn it
on.
How do you turn it off?

Thanks Lucid.
 
L

Lucid

Hrm, if you didnt turn it on yourself its more than likely not on, but if
you want to check look at the source of the offending page up at the top it
will have trace="true".
 
J

Jim in Arizona

Well damn Bruce! I think you just saved me a lot of time and frustration!
Thanks!
It's often something small, isn't it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top