Results 1 to 9 of 9

Thread: Creating Buttons and text fields dynamicaly

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    56

    Creating Buttons and text fields dynamicaly

    Hi,

    I want to create several textboxes and buttons in my page.
    Each button has a unique ID, an they all must call the same function, but will behave defferently, like by passing a parameter...

    Do you have any idea how i can do that ???


    Regards
    Ahmed Abughoush
    Last edited by ahmedabugh; May 7th, 2005 at 12:34 AM.

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: Creating Buttons and text fields dynamicaly

    hmmm. It sound slike you need to create a fucntion and pass parameters to it on the button click

    Code:
    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
      Dim strFileName As String = "test.csv"
      Dim strFileLocation As String = "C:\Inetpub\wwwroot\reports\"
      Export(strFileLocation & strFileName, dsResults.Tables(0))
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    56

    Re: Creating Buttons and text fields dynamicaly

    Dear davebat;
    This function only runs at a button click, but i did not understand the part which submits the parameters..

    I didn't get this part

    Thanks

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Creating Buttons and text fields dynamicaly

    Why not assign a different CommandName property to each button and then you can use this in the shared click handler.

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    56

    Re: Creating Buttons and text fields dynamicaly

    Hi...
    Can you guide me how i can do that ???

    Thanks

  6. #6
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Creating Buttons and text fields dynamicaly

    First create button and assign a CommandName and event handler.
    Code:
    Button btnNew = new Button();
    btnNew.ID = "btnNew";
    btnNew.Text = "Click me";
    btnNew.CommandName = "Button_Clicked";
    btnNew.Click += new EventHandler(btnNew_Click);
    Obviously you'll have to add this to a control collection somewhere to make it appear on the page.

    Then within the event handler you can access the CommandName property:
    Code:
    void btnNew_Click(object sender, EventArgs e) {
    if (sender.CommandName == "Button_Clicked") {
    //The dynamic button was clicked!
    }
    }
    HTH

    DJ
    Last edited by dj4uk; May 7th, 2005 at 05:11 AM.

    If I have been helpful please rate my post. If I haven't tell me!

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    56

    Re: Creating Buttons and text fields dynamicaly

    Wow...
    Thanks a lot dj4uk

    Thats exactly what i needed

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2005
    Posts
    56

    Re: Creating Buttons and text fields dynamicaly [RESOLVED]

    One more thing....

    How can i place them in my webpage... ??
    Can I add them as to a cell in a table object ??

  9. #9
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Creating Buttons and text fields dynamicaly

    Add placeholder controls wherever you might want to add controls. If you don't add anything then nothing is displayed on the page.

    To add a control just do the following after you have created the control dynamically.

    Code:
    phldNew.Controls.Add(btnNew);
    where phldNew is the placeholder control ID.

    HTH!

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

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