As of right now my code works to where you select how many players and hit enter and it outputs enter Players Name and has that many textboxes. Works Great...
Is having mutiply Sumbit buttons a bad idea? Well my idea behind the entering of the names is once the names are entered. I would like to have my code save the names, because I'm working on a randominzer. I have a list of stuff in the back end. and so when
the user enters the names of the players. Then my program loops through and displays. Like for instances you enter 3 names, Shawn, Sam, and Wendy. and hit enter and it loops through my list and displays back tot he user... Sam get blue, Shawn get red,
Wendy get orange.....Hope this helps
CSharpMom
Marked as answer by CSharpMom on Dec 27, 2012 07:33 PM
In that case, you only need one button. Let the user type in all the names and then click the submit button. You can validate to make sure all the textboxes were filled in. If they were, save all the names and continue the code - the loops and randomize
etc.
Marked as answer by CSharpMom on Dec 27, 2012 07:33 PM
And yes, having multiple submit buttons is a bad idea. Its confusing for the user - they have no idea why there are a few submit buttons. Usually you complete the whole page and then just hit one button, not a button for every input. You also have to create
click events for each button. And if they all fire the same click event (eliminating the need to create multiple events) then just have 1 button!
Marked as answer by CSharpMom on Dec 27, 2012 07:33 PM
The easiest way would probaby be to have a submit button on top of the page next to the drop down list and another submit button on the bottom of the page which is disabled until the user selects the number of players and the textboxes load. This way you
don't have to create the submit button dynamically - its there from the get-go, yet it does not confuse the user. They know to only use it to submit the names they entered in the text boxes.
You may want to try using the dropdownlist's selected index changed event to load the textboxes instead of having a submit button. You should still have the other submit button disabled until the textboxes populate.
Marked as answer by CSharpMom on Dec 27, 2012 07:33 PM
CSharpMom
Member
5 Points
11 Posts
adding text boxes one after the other
Nov 27, 2012 04:20 PM|LINK
As of right now my code works to where you select how many players and hit enter and it outputs enter Players Name and has that many textboxes. Works Great...
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
int numberOfPlayers = int.Parse(selectPlayers.Value);
for (int i = 0; i < numberOfPlayers; i++)
{
TextBox tb = new TextBox();
Label1.Text = "Enter Player's Name";
tb.Width = 100;
form1.Controls.Add(tb);
}
}
}
}
}
Would like to take it another step and have it look like this:
lets say i selected 3 players - so it will look like this
Enter Player's Name a textbox to enter the name and a submit button
Enter Player's Name a textbox to enter the name and a submit button
Enter Players's Name a textbox to enter the name and a submit button
if you select 4 and hit sumbit it shows 4 enter players name a textbox and a sumbit button
if you select 5 and hit submit it shows 5 enter your name and a submit button and so on.....
Hope I am clear enough.... Thanks
msmk
Participant
797 Points
180 Posts
Re: adding text boxes one after the other
Nov 27, 2012 05:26 PM|LINK
Why do you want multiple submit buttons? Is each button firing its own event or are they all firing the same event?
CSharpMom
Member
5 Points
11 Posts
Re: adding text boxes one after the other
Nov 28, 2012 05:25 PM|LINK
Is having mutiply Sumbit buttons a bad idea? Well my idea behind the entering of the names is once the names are entered. I would like to have my code save the names, because I'm working on a randominzer. I have a list of stuff in the back end. and so when the user enters the names of the players. Then my program loops through and displays. Like for instances you enter 3 names, Shawn, Sam, and Wendy. and hit enter and it loops through my list and displays back tot he user... Sam get blue, Shawn get red, Wendy get orange.....Hope this helps
CSharpMom
msmk
Participant
797 Points
180 Posts
Re: adding text boxes one after the other
Nov 28, 2012 05:30 PM|LINK
In that case, you only need one button. Let the user type in all the names and then click the submit button. You can validate to make sure all the textboxes were filled in. If they were, save all the names and continue the code - the loops and randomize etc.
msmk
Participant
797 Points
180 Posts
Re: adding text boxes one after the other
Nov 28, 2012 05:34 PM|LINK
And yes, having multiple submit buttons is a bad idea. Its confusing for the user - they have no idea why there are a few submit buttons. Usually you complete the whole page and then just hit one button, not a button for every input. You also have to create click events for each button. And if they all fire the same click event (eliminating the need to create multiple events) then just have 1 button!
CSharpMom
Member
5 Points
11 Posts
Re: adding text boxes one after the other
Nov 28, 2012 05:45 PM|LINK
Ok, thanks for the advise, makes sense.. But how do i put a submit button after the boxes. when i'm not sure how many boxes will be displayed...
as of right now my page looks like this:
Select Number of Players--a drop down list( of numbers from 2-12) and a sumbit button
the user selects 3 for instance. my page then displays under this
Enter Player's Name and has three textboxes.
but if a user selects 12 then it will be 12 textboxes displayed...See my problem...
msmk
Participant
797 Points
180 Posts
Re: adding text boxes one after the other
Nov 28, 2012 05:55 PM|LINK
The easiest way would probaby be to have a submit button on top of the page next to the drop down list and another submit button on the bottom of the page which is disabled until the user selects the number of players and the textboxes load. This way you don't have to create the submit button dynamically - its there from the get-go, yet it does not confuse the user. They know to only use it to submit the names they entered in the text boxes.
You may want to try using the dropdownlist's selected index changed event to load the textboxes instead of having a submit button. You should still have the other submit button disabled until the textboxes populate.
CSharpMom
Member
5 Points
11 Posts
Re: adding text boxes one after the other
Nov 28, 2012 06:03 PM|LINK
hum, you lost me.. :)
Here is my code right now...
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
int numberOfPlayers = int.Parse(selectPlayers.Value);
for (int i = 0; i < numberOfPlayers; i++)
{
TextBox tb = new TextBox();
Label1.Text = "Enter Player's Name";
tb.Width = 100;
form1.Controls.Add(tb);
}
and it works fine....
msmk
Participant
797 Points
180 Posts
Re: adding text boxes one after the other
Nov 28, 2012 06:30 PM|LINK
I'm sure it does! I was imagining it a bit differently but this looks great too.
So just add 1 button dynamically, after the for loop which adds the textboxes:
Button btnSubmit = new Button();
btnSubmit.Text = "Submit";
btnSubmit.Click += new EventHandler(btnSubmit_Click);
form1.Controls.Add(btnSubmit);
Then create the btnSubmit_Click method:
protected void btnSubmit_Click(object sender, EventArgs e)
{
//do your stuff here when the click event happens
}
CSharpMom
Member
5 Points
11 Posts
Re: adding text boxes one after the other
Nov 28, 2012 10:32 PM|LINK
Ok, sorry haven't responded till now. Been trying to get this to work as well has tending to kids.
.I got it to work once then I kept getting this message...btnSubmit_Click does not exist in the current context...