How to restore label's text across postbacks when it is changed by client-side script?

Hello all,

I have a page that uses AJAX to check info entered in textboxes and display results by changing the text of labels underneath the textboxes. Since label's value/text is not submitted by the form, I use hidden fields (that are updated together with the labels) to restore the text of labels across postbacks. The question is: is there any nicer way of doing that? Maybe I should use some other control, instead of labels, the value of which is submitted?

Thank you.

5/21/2008 6:56:23 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 55

It depends on what your ajax call is doing.  If it's a webservice call, or any of the ajax framework's that don't work with post-back's, then there's not much you can do other than what you're doing now.  I would suggest wrapping your label & input's into a control if possible to keep things cleaner.

Now if you're using the ajax framework and you're actually doing a post-back to the server ( update panel , you could instead store the result in the viewstate along with setting your label's text.  It would then be available on subsequent requests.

5/21/2008 7:10:16 PM

With AJAX I'm actually posting back to a different aspx page, that runs sql query in the code behind and returns the result in its body, which is then read by the main page and used to update the labels.

5/21/2008 7:22:38 PM

In that case, I think you're already doing it the only way you can, which is by using hidden fields.

 Like I said before, try and wrap the functionality into a seperate control if possible, this will keep the code cleaner and allow for re-use in the future.

5/21/2008 8:20:52 PM

Similar Artilces:

How to Access/Pass Server Side Array Variable at Another Web Form's Client Side
Hi All,I struck up with some intrested senario at my application development...hope some body will guide me or sends me some code snippets....Thanks in advance.Senario is like A.aspx (using C# .net 2.0 as code behind) I am going to have a array variable basically it is an TWO Dimensional array after populating the values in array I need to redirect/ reload another web form B.aspx, here i need to access the array in B.aspx client side JavaScript.How can I do this...Thanks AgainRaju Dont do a redirect but use server.transfer. That way the previous page will still hold its value, ...

Can you change a linkbutton's text using client side javascript?
I have a linkbutton which opens a new window. When the user closes the new window, I want to change the text of the original linkbutton. The issue isn't the popup window since know how to use window.opener. The problem is that I don't know how to use javascript to change the inner text of the linkbutton which I know is rendered as anchor tags. Any suggestions? Hi, on the Page where the LinkButton is, you can output the client-side ID of the LinkButton with it's ClientID property assuming you have <asp:LinkButton ID="LinkButton1" runat="server" Text="Hello" />So you could ou...

Setting Label's text attribute to the page title's text.
Is there a way to programmatically set a label's text attribute to the current page's title attribute? Such as (pseudo code):  private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here lblPageTitle.Text = PageTitle.Text.Attribute(); }   lblPageTitle.Text = Page.Title();  Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: Thank you for the reply, however, Page.Title is not available. Perhaps this is a 2.0 feature...

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Can I change a treeview's text size depending on what my browser's text size is set to?
I'm using a treeview on a .net 2.0 page and all is working fine with it in Internet Explorer.  However if I go to View -->  Text Size --> Largest on my browser's menu, all the text on my page appears huge apart from the text in the treeview which remains the same size as it always was.  Is there a way to fix this so that this text will also increase in size? Many Thanks. Make sure the font size is not set in the control.  And use css to help moderate your pages look and feel. HTH,Joe JohnstonIf a picture is worth a 1000 words, a sample application ...

What does Google's new web browser (Chrome) mean to client-side web developers?
Google announced it's new web browser (Chrome) yesterday. This browser offers tab browsing with each tab running in a separate processes, increased performance, and more. Read more here: Chrome like Safari and Konqueror is based on the Webkit / KHTML rendering engine. After a single day Chrome aparently has a 2% market share. What does Google's Chrome mean to client-side web developers? - Adam Kahtava [] Interesting link to the comic book, I didnt realised that they had gone so deep in to it design wise. F...

Can't open doc's across PO's in "live" mode over the web...
Using GWise 6.5, NetWare 6.0 The POA's are NAT'd through our firewall. In our production environment we have 4 POA's with approx. 30 libraries spread out among them. The libraries are created under the PO's. Each PO has it's own set of libraries and does both email & library processing. In our test environment, I have 1 PO for email only (no libraries) and another PO for documents only (no email) with a library created under it. The following error happens in both environments: When users are logged into GWise from outside the LAN in "live...

How do I handle Updating a Label's Text When it's in a Template?
As it stands right now.  I get the error 'Object reference not set to an instance of an object.' for the following line of code.vd_lbl_StatusMess.Text = "Record Updated" This label is located in a Template.  I just want to update the text property.  Thats all!!  Working with Templates has been a nightmare!!  Please help! "Sometimes I spend so much time going the wrong direction on a problem. K.I.S.I.S = Keep It Simple I'm Stupid :)"Matt Is the Template in a Formview or Gridview?  I'm asking because if 'ts a Formview, you have to find t...

Changing label's text through RadioButtonList
Hi!   I have RadioButtonList(rbl1 and rbl2) and Label1 and when someone click on rbl2, how i can change text of Label1. Also, I have set rbl1 as default selected. So when somone click back to rbl1, the default text of Label1 should be appearing. Can anyone please tell me what code should be written. protected void RadioButtonList_SelectedIndexChanged(object sender, EventArgs e) { } Thanks for your answer. R Patel To make a default selection you can set a property on the radiobutton list,I don't remember what it is called but check the properties list in VS. to set the text...

How to change txt2.text when the txt1's.text changes using JavaScript?
Hello! I want some JavaScript (or any other client-side) solution for my problem thatdescribed here: In a few words, my problem is that i don't know the way to change the txt2.text valuewhen the txt1.text value changes... Please read the first...I want only JavaScript solution... Thank you very much! Like this? <input type="text" id="TextBox1" name="TextBox1" onchange="textBox1OnChange(this);" runat="server" /><input type...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

How do I change a label's text (twice) in an UpdatePanel?
Hey, I would like for a user to click an 'Add to Cart' Button, a message appears 'Adding Item to Cart ...', and then the message changes to 'Item added to Cart' when finished.  I have under the AddToCart_Click event changing the label to 'Adding to Shopping Cart ...' then the code to actually add the item to the shopping cart and then changing the label to 'Item added to Cart.'  However, only the last label is seen (Item added to Cart).  Any suggestions on how to do this?  Should I use 2 Update Panels?  Or, how do I tell it to...

How to change label's text inside a datalist
I been working on this too long can someone help. lbtotal's text is setted to 55 I want to change the value of the label lbtotal inside a datalist. So how can do it? Also if I used too much seesion variable would it slow down my loading speed? thank you all Hello thank you bump...

Server Req's for Client-Side Scripting
Hi, I'm not sure where's the best place to ask this, but is there a server requirement in order for the client to be able to execute a client-side script using laguage PerlScript. Javascript and VBScript work fine, but my client-side PerlScript function doesn't execute at all when I upload the file Geocities. It does execute when I run it on my local machine (which has Perl installed). I though I just needed to install the ActiveX scripting engine for PerlScript on the client and that's it. Does any one have any information on this. Thanks. If any of you...

Web resources about - How to restore label's text across postbacks when it is changed by client-side script? -

Resources last updated: 12/25/2015 8:26:40 PM