Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Web Control Problem

Web Control Problem

Scheduled Pinned Locked Moved ASP.NET
designsysadminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marin007
    wrote on last edited by
    #1

    I am trying to make a simple control with a button and a label. When you click the button the text of the label should change from "A" to "B" but it doesn’t work. Can anybody tell me what am I doing wrong? using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace WebControlLibrary1 { [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server>")] public class WebCustomControl1 : System.Web.UI.WebControls.WebControl { private Button b; private Label l; public WebCustomControl1() { b=new Button(); b.Text="Click me!"; b.Click+=new EventHandler(this.b_Click); l=new Label(); l.Text="A"; } private void b_Click(object sender, System.EventArgs e) { l.Text="B"; } protected override void Render(HtmlTextWriter output) { b.RenderControl(output); l.RenderControl(output); } } }

    F 1 Reply Last reply
    0
    • M marin007

      I am trying to make a simple control with a button and a label. When you click the button the text of the label should change from "A" to "B" but it doesn’t work. Can anybody tell me what am I doing wrong? using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace WebControlLibrary1 { [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server>")] public class WebCustomControl1 : System.Web.UI.WebControls.WebControl { private Button b; private Label l; public WebCustomControl1() { b=new Button(); b.Text="Click me!"; b.Click+=new EventHandler(this.b_Click); l=new Label(); l.Text="A"; } private void b_Click(object sender, System.EventArgs e) { l.Text="B"; } protected override void Render(HtmlTextWriter output) { b.RenderControl(output); l.RenderControl(output); } } }

      F Offline
      F Offline
      fadee
      wrote on last edited by
      #2

      Here enjoy... using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace WebControlLibrary1 { /// /// Summary description for WebCustomControl1. /// [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server>")] public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, IPostBackEventHandler, INamingContainer { private Label l; private Button b; /// /// Render this control to the output parameter specified. /// /// The HTML writer to write out to public WebCustomControl1() { b = new Button(); b.Text = "button"; b.Click += new EventHandler(this._Handler); b.Width = 100; l = new Label(); l.Text = "A"; } protected override void CreateChildControls() { Controls.Add(b); Controls.Add(l); } private void _Handler(System.Object sender, System.EventArgs e) { l.Text = "B"; } public void RaisePostBackEvent(string Args) { // This function is supposed to handle post back events. } } } --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.

      M 1 Reply Last reply
      0
      • F fadee

        Here enjoy... using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace WebControlLibrary1 { /// /// Summary description for WebCustomControl1. /// [DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server>")] public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, IPostBackEventHandler, INamingContainer { private Label l; private Button b; /// /// Render this control to the output parameter specified. /// /// The HTML writer to write out to public WebCustomControl1() { b = new Button(); b.Text = "button"; b.Click += new EventHandler(this._Handler); b.Width = 100; l = new Label(); l.Text = "A"; } protected override void CreateChildControls() { Controls.Add(b); Controls.Add(l); } private void _Handler(System.Object sender, System.EventArgs e) { l.Text = "B"; } public void RaisePostBackEvent(string Args) { // This function is supposed to handle post back events. } } } --------------------- A gasp of breath, A sudden death: The tale begun. A rustled page Passes an age: The tale is done.

        M Offline
        M Offline
        marin007
        wrote on last edited by
        #3

        Thanks... It works now.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups