Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
My initial goal is to achieve followings 1. Render dynamic TextBox in custom editor webpart 2. Manage Text (, visibility, height, width etc) of the TextBox from editor part. 3. We can consider Sharepoint webpart or asp.net webpart framework

I have tried following way ( with asp.net webpart framework) but can not achieve initial goal.

C#
 //CustomWebPart.cs
 private string _text;
 [WebBrowsable(false)]
 [Personalizable(PersonalizationScope.Shared)]
 public string Text
 {
    get { return _text; }
    set { _text = value; }
 }
 protected override void CreateChildControls()
 {
    TextBox txt = new TextBox();
    txt.Text = Text;
    Controls.Add(txt);
 }

//CustomEditor.cs
 private TextBox txtExample;
 protected override void OnInit(EventArgs e)
 {
    base.OnInit(e);
    txtExample= new TextBox();
 }
 protected override void CreateChildControls()
 {
    Controls.Add(txtExample);
 }
 public override bool ApplyChanges()
 {
     EnsureChildControls();
     CustomWebPart part = WebPartToEdit as CustomWebPart;
     if (part != null)
     {
          part.SqlQuery = txtExample.Text;
     }
 }
 public override void SyncChanges()
 {
    EnsureChildControls();
    CustomWebPart part = WebPartToEdit as CustomWebPart;
    if (part != null)
    {
        txtExample.Text = part.SqlQuery;           
    }
 }


Problem is very clear and normal:
After changing text from editor webpart once I click on OK or Apply button system first fire CreateChildControls() event of CustomWebpart.cs before firing ApplyChanges() even before firing CreateChildControls() of CustomEditor.cs , as a result Textbox of the webpart can not update on time.

So, how can we render asp.net server side controls in webpart and manage( changing text, visibility, width, height, etc) from editor part. ?

Have any idea?
Posted
Updated 22-Sep-12 16:49pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900