views:

788

answers:

3

Is there a way to make Response.Write work in an UpdatePanel and not cause the app to error out for obvious reasons? Or, is there a way to get similar results without more than one line of code in C#?

+1  A: 

You could just put a literal control inside your update panel and have the same effect using:

myLiteral.Text += "Some more text!";
Spencer Ruport
crap, I suspected that. that's what I was doing before :-(
craigmoliver
A: 

The only way to get similar behavior (loosely similar) is to put a label within an update panel that is getting updated on that partial postback, and set its value to something (which would only take the one line of code to set it)... the rest of the page simply isn't getting updated, so there's nothing you can do.

Why do you want this functionality anyways?

Max Schmeling
A: 

Response.Write does not work with UpdatePanels, but as Spencer mentioned, you can put your info in a literal.

Another option is to use the System.Diagnostics.Debug.Assert() function, if you're debugging. The advantages to this are

  1. you can put these in your code and they will be compiled out of a release,
  2. you can place these in places where errors SHOULD NOT EVER occur, but will pop up to let you know when they do (only when you're debugging), and
  3. your code will pause functioning at the Assert line, so you know exactly what's going on where you put that Assert.

As with anything, don't go overboard and put them everywhere, but I've found it to be a very useful debugging tool.

Jason