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#?
5 Answers
You could just put a literal control inside your update panel and have the same effect using:
myLiteral.Text += "Some more text!";

- 34,865
- 12
- 85
- 147
-
crap, I suspected that. that's what I was doing before :-( – craigmoliver Aug 19 '09 at 21:01
Just found this could be helpful to other people.
you cannot use Response.Write or Response.Redirect inside update panel.
To solve this you have to use Trigger. This is used to make a server trip from inside an update panel
<asp:UpdatePanel ID="UpdatePanel9" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnExcel" />
</Triggers>
<ContentTemplate>
---Your code here
</ContentTemplate>
Here the ControlID is the button or other control. For example in the button click event you can write some text in the response.

- 21
- 2
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?

- 12,363
- 14
- 66
- 109
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
- you can put these in your code and they will be compiled out of a release,
- 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
- 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.

- 51,583
- 38
- 133
- 185
A simple solution to this problem I use is to call JQuery function html() insted calling Response.Write()... For example, lets say I wanna update some html text inside UpdatePanel I would do something like this:
With Response.Write(), it would be simple as this: Response.Write("[TextToBeAddedToHTML]");
But with Jquery its little complicated, and you have to include Jquery library to Html page:
ScriptManager.RegisterStartupScript(this, GetType(), "TextUpdate", "$(\"#[ID_OF_HTML_Element]\").html(\"<p>" + [TextToBeAddedToHTML] + "</p>\");", true);

- 1
- 1
-
Why did you delete the post at http://stackoverflow.com/questions/3872844/how-to-write-response-write-within-update-panel/16384971#16384971 ? It looks fine. I just format the post. – nhahtdh May 05 '13 at 13:29
-
hahaha, my first post, and im looking for the right place to put it on... :))) – Filip Zivanovic May 05 '13 at 13:33