Click here to Skip to main content
15,896,154 members

Render TextBox (sever control) in WebPart and manage (text, visibility etc of) the server controls from editor part

Shahdat Hosain asked:

Open original thread
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?
Tags: C#, Sharepoint, ASP.NET, WebParts

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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