Apr 18, 2011

Dynamic control in asp.net 3.5

default.aspx
<!--
 <div>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"
            style="height: 26px" />
 </div>
--!>

default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
    {
        TextBox new_textbox = new TextBox();
        new_textbox.ID = "txt" + 1;
        new_textbox.Text = "";
        PlaceHolder1.Controls.Add(new_textbox);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string OptionID = "txt" + 1;
        TextBox tb = (TextBox)PlaceHolder1.FindControl(OptionID);
        Response.Write(tb.Text);
   
    }






No comments:

Image Gallery - Image Add/Delete/Preview - Single Page App -

https://github.com/TheKalin/jQuery-File-Upload.MVC5 Helper Class / Models   public class FilesHelperDB     {         dbImageGallery...