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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to maintain viewstate of a runtime generated control

how to maintain viewstate of a runtime generated control

Scheduled Pinned Locked Moved ASP.NET
tutorial
6 Posts 5 Posters 1 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.
  • K Offline
    K Offline
    krishnaveer
    wrote on last edited by
    #1

    Hi guys I am generating a runtime htmltable, there are checkboxes whatever is selected after post back i want to keep this as it is(as before postback) code for generating run time table Dim tr1 As New HtmlTableRow Dim txtbox As New TextBox Dim chkbox As New CheckBox Dim lbl As New Label Dim td1 As New HtmlTableCell Dim td2 As New HtmlTableCell Dim td3 As New HtmlTableCell txtbox.ID = "xyz" & M chkbox.ID = "abc" & M lbl.ID = "ijk" & M lbl.Text = dsFill.Tables(0).Rows(M).Item("size") txtbox.Width = "30" txtbox.Height = "12" lbl.Font.Size = "8" chkbox.Height = "8" lbl.Width = "80" chkbox.ToolTip = "Click here which size you want" txtbox.ToolTip = "Fill required quantity" td1.Controls.Add(lbl) td2.Controls.Add(chkbox) td3.Controls.Add(txtbox) tr1.Cells.Add(td1) tr1.Cells.Add(td2) tr1.Cells.Add(td3) TABLE2.Rows.Add(tr1) what will be solution please suggest me Thanks In Advanced

    krishna veer singh

    C A 2 Replies Last reply
    0
    • K krishnaveer

      Hi guys I am generating a runtime htmltable, there are checkboxes whatever is selected after post back i want to keep this as it is(as before postback) code for generating run time table Dim tr1 As New HtmlTableRow Dim txtbox As New TextBox Dim chkbox As New CheckBox Dim lbl As New Label Dim td1 As New HtmlTableCell Dim td2 As New HtmlTableCell Dim td3 As New HtmlTableCell txtbox.ID = "xyz" & M chkbox.ID = "abc" & M lbl.ID = "ijk" & M lbl.Text = dsFill.Tables(0).Rows(M).Item("size") txtbox.Width = "30" txtbox.Height = "12" lbl.Font.Size = "8" chkbox.Height = "8" lbl.Width = "80" chkbox.ToolTip = "Click here which size you want" txtbox.ToolTip = "Fill required quantity" td1.Controls.Add(lbl) td2.Controls.Add(chkbox) td3.Controls.Add(txtbox) tr1.Cells.Add(td1) tr1.Cells.Add(td2) tr1.Cells.Add(td3) TABLE2.Rows.Add(tr1) what will be solution please suggest me Thanks In Advanced

      krishna veer singh

      C Offline
      C Offline
      Chetan visodiya
      wrote on last edited by
      #2

      Put the above code in page load event and make sure that this code will execute for every request(wheather it is postback or not).

      K 1 Reply Last reply
      0
      • C Chetan visodiya

        Put the above code in page load event and make sure that this code will execute for every request(wheather it is postback or not).

        K Offline
        K Offline
        krishnaveer
        wrote on last edited by
        #3

        Ya it is on page load but i want to maintain what ever is selected or checked before postback

        krishna veer singh

        M L 2 Replies Last reply
        0
        • K krishnaveer

          Ya it is on page load but i want to maintain what ever is selected or checked before postback

          krishna veer singh

          M Offline
          M Offline
          Milind R Chavan
          wrote on last edited by
          #4

          Hi When you generate the Html table from codebehind, just put Html table in to session variable and follow code : on class level declare: static bool createAgain = false; in you function : Session["TABLE2"] = TABLE2; createAgain = true; Write following methods to maintain states: protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); Control control = GetPostBackControl(this.Page); if ((control != null) || createAgain) { //should be set before the CreateUserControl method createAgain = true; CreateUserControl(controlID); } } protected Control GetPostBackControl(Page page) { Control control = null; try { string ctrlName = page.Request.Params.Get("__EVENTTARGET"); if (ctrlName != null && ctrlName != String.Empty) { control = page.FindControl(ctrlName); } } return control; } protected void CreateUserControl(string controlID) { // createAgain field is set to true in the OnPreInit method // when the 'Create User Control' button is clicked // the createAgain field is used to check if the // user control is on the page before the call // if so create the control again and add it to the // Control Hierarchy again if (Session.Count > 0) { for (int i = 0; i < Session.Count; i++) { switch (Session[i].ToString()) { case "ASP Control": // Write your control name { //Add control to placeholder or div break; } } } } } } Please modify the code according to your requirment Regards, Milind

          1 Reply Last reply
          0
          • K krishnaveer

            Hi guys I am generating a runtime htmltable, there are checkboxes whatever is selected after post back i want to keep this as it is(as before postback) code for generating run time table Dim tr1 As New HtmlTableRow Dim txtbox As New TextBox Dim chkbox As New CheckBox Dim lbl As New Label Dim td1 As New HtmlTableCell Dim td2 As New HtmlTableCell Dim td3 As New HtmlTableCell txtbox.ID = "xyz" & M chkbox.ID = "abc" & M lbl.ID = "ijk" & M lbl.Text = dsFill.Tables(0).Rows(M).Item("size") txtbox.Width = "30" txtbox.Height = "12" lbl.Font.Size = "8" chkbox.Height = "8" lbl.Width = "80" chkbox.ToolTip = "Click here which size you want" txtbox.ToolTip = "Fill required quantity" td1.Controls.Add(lbl) td2.Controls.Add(chkbox) td3.Controls.Add(txtbox) tr1.Cells.Add(td1) tr1.Cells.Add(td2) tr1.Cells.Add(td3) TABLE2.Rows.Add(tr1) what will be solution please suggest me Thanks In Advanced

            krishna veer singh

            A Offline
            A Offline
            Abhijit Jana
            wrote on last edited by
            #5

            You have to create the control before PageLoad(). Please read ASP.NET Page life cycle, which will give a clear idea that why we need to do that.

            cheers, Abhijit CodeProject MVP

            1 Reply Last reply
            0
            • K krishnaveer

              Ya it is on page load but i want to maintain what ever is selected or checked before postback

              krishna veer singh

              L Offline
              L Offline
              luckystar09
              wrote on last edited by
              #6

              I'm very interested! I would love to find out more. :omg: :omg: [url=http://globolstaff.com/\][color=#EDF8FF][u]website maintain[/u][/color][/url]

              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