Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

Monday, March 26, 2012

AJAX to grab a server controls RenderContents() output

Hi everyone,

My web application dynamically loads custom built server controls at runtime from seperate assemblies using the reflection namespace. Everything works fine, and the server controls display on the page as required.

I would like to extend this, to enable the server controls to be displayed asycronously. Is it possible to make an asynronous request to the web server and then when the server control is loaded, pass back the HTML that is generated in the RenderContents() method as the responseText?

How would I go about doing this? Example code would be great.

Any help is much appreciated,
Ad

Hi,

I'm still stuck on this on this one, any ideas?

Thanks again,
Ad


Hi,

Please refer to this:Emailing the Rendered Output of an ASP.NET Web Control, it implements the function you need.

Hope this helps.

NOTE:This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


This link looks like a good start, but a bit more sample code especially on the Ajax part would be very helpful.

Regards

Dion


Hi Dion,What probelms do you have after you've got the output of a control?

Saturday, March 24, 2012

AJAX Timer doesnt work with page trace

Whenever I trace the output of my site, I get the following error: sys.webforms.pagerequestmanagerparsererrorexception. message from the server cannot be parsed. common causes of this error are when the resposne is modified by calls to response.write, response filters, httpmodules, or server trace is eneabled.

Error parsing near [timer1,1000], etc......

and it's an alert pop-up, that continues to alert every second after I close it. Its really annoying.


The site works fine when trace isn't eneabled, but obviously trace is needed for debug reasons.

I can catch the trace event in Page.Trace.IsEnabled, but how do I destroy or deactivate the timer, or the scriptmanager, or whatever it is that causing all these javascript alerts?

Hi bbaxter,

In general trace won't "play nice" with ajax (as it alters the page by appending the trace information to it).

I'd suggest taking a look atthis page to see how Microsoft recommends handling Debug and Trace situations when Ajax is involved.

You can use thetrace viewer to avoid appending the information to the page.

Add something like this to your web config

<configuration>
<system.web>
<trace enabled="true" pageOutput="false" requestLimit="50" localOnly="false"/>
</system.web>
</configuration>

And surf to http://yourapplication/trace.axd

I hope that helps.


Page level Tracing is not enabled if the page contains UpdatePanel, Instead use Trace.axd.

Well, see I have a page class that only sets trace=true when the url contains a ?trace=1 argument.

Can't I programmatically just ignore the update panel when trace=1, or using page.trace.isenabled in the page load?

Basically what I'm saying is on every page of our site adding ?trace=1 makes the trace enabled, this is useful for testing and live because you can see the debug information. Is there a way to just make the popups stop... popping up? the trace isn't the problem I suppose, the popups caused by the timer are.


Hi bbaxter,

Ah I see...I'd suggest looking at migrating to the suggested way of doing this. Any use of updates panels and trace will cause the errors you are seeing. There may be a way to eat those exceptions (I'm not aware of one) but it's not going to update the updatepanel, making it rather pointless.

I think the best way is probably to set the EnablePartialRendering property on your script manager to false wherever you're manually turning on tracing. That will eliminate the ability for updatepanels to do asynchronous postbacks. You probably also want to set the Timer.Enabled property to false or change its Interval to something longer as it'll cause regular postbacks that will refresh the page.

I hope that helps.