Wednesday, March 28, 2012

updatepanel

Hi,

I am using updatepanel to update a message that's to be show to the user. I have a textbox with the submit button inside another updatepanel. Once the user hits a submit I have to display whatever he entered in the textbox.

The problem I am having is that the div (which displays result, can a server side control too), just appends the new text to the original value. So if I hit enter a multiple times, it goes on appending!

Am I missing something here?

Thanks!

Can you show the code that move the text from the textbox to the div?


Please show an example of what you are doing.


HtmlGenericControl DivControl = new HtmlGenericControl();

DivControl = (HtmlGenericControl)ResultsDiv;

DivControl.InnerHTML = txtReply.Text;

This comes up when the submit button's pressed.


Is there some reason you couldn't use a Label inside the div as your target? (I'm just trying to prevent the innerHTML thing from being the issue...)


hi, no, I tried label too. but did not work out. If you can paste the code for that, it would be really helpful.

Thanks!


I'm not sure why your code isn't doing what you expect it to, but here's some code that seems to work fine, using a Label:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void button_click(object sender, EventArgs e) { Label1.Text = TextBox1.Text; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="button_click" /> <asp:Label ID="Label1" runat="server" /> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

Just a Small Correction, As you want to append the Text each time the button is pressed, the click handler should be:

protected void button_click(object sender, EventArgs e)
{
Label1.Text += TextBox1.Text;
}

Everything else is fine with the above example.


I thought he explicitlydidn't want to append?

From original post: "The problem I am having is that the div (which displays result, can a server side control too), just appends the new text to the original value. So if I hit enter a multiple times, it goes on appending!"


Sorry my mistake, the Requirment is not to append.


Hi mate, works like a charm! Thanks!

No comments:

Post a Comment