c# - Dynamic Div creation asp.net -
I'm trying to dynamically create div on the bilateral button click.
For this, I link it to & gt; & Gt;
and the code was formatted as follows on the server side (.cps page) & gt; & Gt;
public fixed int i = 0; Protected Zero Button 1_Click (Object Sender, EventArgs e) {i ++; HtmlGenericControl newControl = New HtmlGenericControl ("div"); NewControl.ID = "newcroll" + i; NewControl.InnerHtml = "This is a dynamically created HTML server control."; PlaceHolder1.Controls.Add (newControl); } This code was giving me one division every time when I pressed the button, I wanted to be apart of divs.
I tried using Javascript on the client & gt; & Gt;
& lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Div & gt; & Lt; ASP: Button ID = "Button 1" Runat = "Server" OnClick = "Button 1" link "Text =" Button "On-clientClick =" addDiv (); "" / asp: place holder id = "place holder 1" run = "server"> gt; script type = "text / javascript" & gt; function addDiv () {warning ("controls in the function"); Var r = document.createElement ('div'); R.style.height = "20px"; R.style.width = "25px"; r.appendChild ("div"); Warning ("Control out of function" These two do not work.
What's wrong with me?
What Any bug
Use this
public index index { Receive (viewstate ["index"] == zero) {seestate ["index"] = 0;} and {viewstate ["index"] = int. Purse (viewstate ["index"]. Toasting ()) + 1;} return int.Parse (seestate ["index"]. ToString ());}} Secure Zero Button 1_Click (Object Sender, EventArgs e) {HtmlGenericControl newControl = new HtmlGenericControl ("div"); NewControl.ID = "newcroll" + index; NewControl.InnerHtml = "This is a dynamically created HTML server control."; PlaceHolder1.Controls.Add (newControl); }
Comments
Post a Comment