|
-
May 4th, 2005, 11:55 PM
#1
Thread Starter
Member
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.
-
May 5th, 2005, 01:45 AM
#2
Fanatic Member
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
-
May 5th, 2005, 01:55 AM
#3
Thread Starter
Member
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
-
May 5th, 2005, 05:24 AM
#4
Frenzied Member
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!
-
May 6th, 2005, 12:21 AM
#5
Thread Starter
Member
Re: Creating Buttons and text fields dynamicaly
Hi...
Can you guide me how i can do that ???
Thanks
-
May 6th, 2005, 03:41 AM
#6
Frenzied Member
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!
-
May 6th, 2005, 01:45 PM
#7
Thread Starter
Member
Re: Creating Buttons and text fields dynamicaly
Wow...
Thanks a lot dj4uk
Thats exactly what i needed
-
May 7th, 2005, 12:34 AM
#8
Thread Starter
Member
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 ??
-
May 7th, 2005, 05:10 AM
#9
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|