Alec Tang

Professional Web Developer/ Web Designer

I build websites based on the latest web standards providing the best possible solution to your company

  • Home
  • About
  • Portfolio
  • Contact
  • Blog
Subscribe Feed

Creating Update Panel in Code Behind Dynamically

Posted by Alec on Mon, 18 Jan 2010, in ASP.NET C#   

Creating Update Panel in code behind dynamically can be a bit tricky, comparing to doing it at the front end. Here's a quick view of the code we write to do this.

UpdatePanel up = new UpdatePanel();
up.ID = "UpdatePanel1";
up.ChildrenAsTriggers = true;
up.UpdateMode = UpdatePanelUpdateMode.Conditional;
this.Controls.Add(up);
this.textBox = new TextBox();
this.textBox.ID = "TextBox";
up.ContentTemplateContainer.Controls.Add(this.textBox);
this.label = new Label();
this.label.Text = "Enter your name.";
up.ContentTemplateContainer.Controls.Add(this.label);
Button button = new Button();
button.Text = "Say Hello";
button.Click += new EventHandler(HandleButtonClick);
up.ContentTemplateContainer.Controls.Add(button);

and a testing event handler:

private void HandleButtonClick(object sender, EventArgs eventArgs)
        {
            this.label.Text = "Hello " + this.textBox.Text;
        }
Comments Be the first to write a comment. Comment gets approved before publishing.

Post Your Comment

Please note: You must be registered to be able to post comments.

Search

 

Latest Posts

  • Auto Complete returns giant list of undefined
  • Integrate Ajax Control Toolkit into Sharepoint
  • Dynamically assign task to user in Sharepoint
  • Getting SPUser from SPQuery programmatically
  • Debug not working for Sharepoint
  • ScriptResource.axd from Ajax getting Too Big
  • Restore list form web part for EditForm
  • Reading and Writing to Lookup Field in Sharepoint
  • Creating Update Panel in Code Behind Dynamically
  • Solution to Hotmail and Email Accounts being hacked

Categories

  • Browsers (1)
  • Projects (1)
  • Web Design (5)
  • Sharepoint (14)
  • Telerik (5)
  • Wordpress (1)
  • Internet (1)
  • SQL (5)
  • LINQ (3)
  • ASP.NET C# (30)
  • JavaScripts (3)
  • IIS (0)
  • Industry (0)
  • Tools (8)
  • SEO (3)

Archives

  • March 2010 (1)
  • February 2010 (4)
  • January 2010 (11)
  • November 2009 (3)
  • October 2009 (1)
  • September 2009 (9)
  • August 2009 (3)
  • July 2009 (4)
  • June 2009 (1)
  • May 2009 (2)
  • April 2009 (8)
  • March 2009 (6)
  • February 2009 (2)
© Copyright 2009 Alec Tang. All Rights Reserved.
This site is conform to W3C Standard XHTML & CSS