Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to retain value of a label during post back(button click) in sharepoint
    primarykey
    data
    text
    <p>While writing code for connecting two webparts,I created a two labels. the text value for both the labels were written in OnPreRender method. However, i forgot to add control for one label in CreateChildControl method. So while debugging, i noticed that, after post back, the <strong>label whose control i forgot to add</strong> didn't retain the value and it <strong>was showing empty string</strong>.But the other <strong>label who's control i added was able to retain the value</strong>. </p> <pre><code>protected override void CreateChildControls() { base.CreateChildControls(); btnup.Text = " Update"; this.Controls.Add(lblid);//**If i add this, the label retains the value during post back , otherwise its null** this.Controls.Add(lblname); this.Controls.Add(lbldesig); this.Controls.Add(tbdes); this.Controls.Add(lblcomp); this.Controls.Add(tbcomp); this.Controls.Add(btnup); btnup.Click += new EventHandler(btnup_Click); } protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (connectionInterface != null) { id = connectionInterface.parameter1; SPWeb mysite = SPContext.Current.Web; SPList mylist = mysite.Lists["UpdateList"]; SPListItemCollection itemcol = mylist.Items; foreach (SPListItem itm in itemcol) { string nm = itm["Company_Id"].ToString(); if (nm.Equals(id)) { lblid.Text = itm["Company_Id"].ToString(); lblname.Text = itm["Name"].ToString(); l } } } else { lblname.Text = "nothing is recieved!"; } } </code></pre> <p>Why is it behaving like this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload