Results 1 to 7 of 7

Thread: Creating buttons at runtime

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    Creating buttons at runtime

    i have a asp.net label that will put a lot of code into my page..this is the best way i saw to make this job..but i wanna put some buttons in there how do i add them to the label in html code so i can use them later? also i dont wanna javascript ones, i wanna asp.net ones that i can use with events etc
    \m/\m/

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I would add a placeholder control to easy the positioning of the buttons and then all you need to do is create the buttons, wire-up the events, and add the button(s) to the placeholder's controls collection. Also, note that you will have to re-create the objects on every postback.

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    could u give an example? for example i have this:
    Label1.Text = "<br></br>";
    i want it to be between the two br tags..how would i do it?
    \m/\m/

  4. #4
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    This should get you started:

    Code:
    private void Page_Load(object sender, System.EventArgs e) {
        Button SayHelloButton = new Button();
        SayHelloButton.Click += new EventHandler(Button1_Click);
        ButtonContainer.Controls.Add(SayHelloButton);
    }
    
    private void Button1_Click(object sender, System.EventArgs e) {
        Response.Write("Hello World");
    }

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i dont get in that where i say which place in my label code is going to have the button
    \m/\m/

  6. #6
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    What exactly are you trying to accomplish? I dont understand why you want to add a button inside of a label. Draw me a picture and I'll see what I can do.

  7. #7

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    the label will contain code like
    label1.text = "<br>hi</br><img src="www........">HERE I WANT A BUTTON<br>hi</br>";
    i hope this is self explanatory....and no i cant put a label, an image control a button and another label..because it has a lot more code and is always repeating..and as i am not connecting to a database i cant use the datalist control
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width