c# - Add multiple textbox .net -


i begin .net , start create dynamically multiple textbox.

i have write :

<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="webapplication1._default" %>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>page sans titre</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:button id="button1" runat="server" text="button" onclick="onclickbutton" />     </div>     <asp:textbox id="textbox1" runat="server"></asp:textbox>     <br />     </form> </body> </html> 

and this

namespace webapplication1 {     public partial class _default : system.web.ui.page     {             protected void page_load(object sender, eventargs e)         {          }         protected void onclickbutton(object sender, eventargs ea)         {             random random = new random();             int randomnumber = random.next(0, 100);              button btnsomebutton = sender button;             btnsomebutton.text = "i clicked!" + randomnumber;              textbox txt = new textbox();             txt.id = "txt_" + randomnumber;             form1.controls.add(txt);         }         } } 

i don't understand why when click 2 time on button1 1 text box appears.

why behavior? way want? thank in advance

everytime click button post back. read on postbacks

the system can handle 1 postback @ 1 time. needs wait the postback return before can process action.

also read page lifecycle enter image description here


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -