Programatically Add Control to ASP.NET C# Page on Button Click -


I want to add fixtures to a special game week on my ASP.NET c # page.

When a user clicks on the add button, then he should make two drop downs so he can choose home and away team. I want to be able to allow as many users as I want to add, so I want a dynamic way of adding control to the page. Once all the fixtures have been added, I want them to save all of them in the database.

Scrolling trough platforms have found the following method to get me control for writing programs:

c #

  Protected Zero AddTeamButton_Click (object Sender, EventArgs e) {DropDownList homeTeamName = new DropDownList (); HomeTeamName.Items.Add ("Arsenal"); HomeTeamName.Items.Add ("Aston Villa"); HomeTeamName.ID = "Homemade"; PlaceHolder1.Controls.Add (homeTeamName); Remove dropdown Remote namespace = new dropdown list (); AwayTeamName.Items.Add ("Arsenal"); AwayTeamName.Items.Add ("Aston Villa"); AwayTeamName.ID = "remote"; PlaceHolder1.Controls.Add (awayTeamName); }   

aspx:

  & lt; Asp: Place Holder ID = "Place Holder 1" Runat = "Server" & gt; & Lt; / Asp: place holder & gt;   

It only creates a set of controls, the second time when you add, nothing happens. Whenever I need to save, it does not even have a Unis ID to access it.

Any ideas how can I solve these issues?

Dynamic control is not all that easy at Asp.net.
You do not need to create them on each post (ideally Init ) on the page.
You must also give them unique ID

If you want to create more than one control, then I suggest to keep a counter in my session and using that loop and on the input Generate necessary controls.

Your AddTeamButton_Click You can only increase the counter and add control of a set.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -