Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. dynamically adding controls

dynamically adding controls

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-net
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BINOVAR
    wrote on last edited by
    #1

    Im adding textboxes in my asp.net page on button click inside a panel,which i have placed in my page. but the new control is getting created ,Im losing the old dyanmically create textbox.here is my code. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click i = Convert.ToInt16(Session(ID)) Dim textbox As New TextBox textbox.ID = "textbox" & i textbox.Text = textbox.ID textbox.Style("top") = "800px" Panel1.Controls.Add(textbox) i = i + 1 Session(ID) = i End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session(ID) = i ' MsgBox(Session(ID)) Else ' MsgBox("2") End If End Sub dont know what is the mistake Im doing.Possibly its anything to do with Viewstate? Thanks in advance

    C 1 Reply Last reply
    0
    • B BINOVAR

      Im adding textboxes in my asp.net page on button click inside a panel,which i have placed in my page. but the new control is getting created ,Im losing the old dyanmically create textbox.here is my code. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click i = Convert.ToInt16(Session(ID)) Dim textbox As New TextBox textbox.ID = "textbox" & i textbox.Text = textbox.ID textbox.Style("top") = "800px" Panel1.Controls.Add(textbox) i = i + 1 Session(ID) = i End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Page.IsPostBack = False Then Session(ID) = i ' MsgBox(Session(ID)) Else ' MsgBox("2") End If End Sub dont know what is the mistake Im doing.Possibly its anything to do with Viewstate? Thanks in advance

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      A textbox that is added dynamically, needs to be added on every postback, or it will disappear. It also needs adding prior to the load event, if you want to interact with it using viewstate, or get events from it.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups