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. Simple Web User Control dynamic parts ...

Simple Web User Control dynamic parts ...

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netdatabasequestion
4 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.
  • O Offline
    O Offline
    Oskars
    wrote on last edited by
    #1

    Hi, I am experienced in C#, but new in ASP.NET. I cannot understand Web page life cycle. If I understand correctly, Web page class is destroyed every time you press the button or something. So I store my properties in ViewState. but there is a problem. I use TextBox to get keyword, which I use for database records retrieval. When i retrieve database records I add dynamically new rows to table with hrefs. private void LoadData() { baseTechPartArray mParts = DataBase3.Get_baseTechPartArray_By_Keyword(KeyWord); for (int i = 0; i <= mParts.Count - 1; i++) { TableRow mRow = new TableRow(); TableCell cellPickup = new TableCell(); TableCell cellName = new TableCell(); TableCell cellCode = new TableCell(); mRow.Cells.Add(cellPickup); mRow.Cells.Add(cellName); mRow.Cells.Add(cellCode); ContainerTable.Rows.Add(mRow); LinkButton hrefName = new LinkButton(); hrefName.Text = mParts.Get(i).name; hrefName.Attributes["record_id"] = mParts.Get(i).id.ToString(); LinkButton hrefCode = new LinkButton(); hrefCode.Text = mParts.Get(i).code; hrefCode.Attributes["record_id"] = mParts.Get(i).id.ToString(); ImageButton mPickupButton = new ImageButton(); mPickupButton.BorderWidth = 0; mPickupButton.ImageUrl = "../Resources/pickup.gif"; mPickupButton.Attributes["record_id"] = mParts.Get(i).id.ToString(); cellPickup.Controls.Add(mPickupButton); cellName.Controls.Add(hrefName); cellCode.Controls.Add(hrefCode); mPickupButton.Click += new ImageClickEventHandler(mPickupButton_Click); hrefCode.Click += new EventHandler(hrefCode_Click); hrefName.Click += new EventHandler(hrefName_Click); cellPickup.Attributes["width"] = "1%"; cellCode.Attributes["width"] = "30%"; } } but Click events does not work until I add Load() method to PageLoad or LoadViewState. But then some of table rows are still from first page load, I try to clear them, but it does`nt help. What simple framework or principle should I use 1)to get work simple onevent -> 2)add dynamic elements with their events -> 3)use dynamically added control events?

    M 1 Reply Last reply
    0
    • O Oskars

      Hi, I am experienced in C#, but new in ASP.NET. I cannot understand Web page life cycle. If I understand correctly, Web page class is destroyed every time you press the button or something. So I store my properties in ViewState. but there is a problem. I use TextBox to get keyword, which I use for database records retrieval. When i retrieve database records I add dynamically new rows to table with hrefs. private void LoadData() { baseTechPartArray mParts = DataBase3.Get_baseTechPartArray_By_Keyword(KeyWord); for (int i = 0; i <= mParts.Count - 1; i++) { TableRow mRow = new TableRow(); TableCell cellPickup = new TableCell(); TableCell cellName = new TableCell(); TableCell cellCode = new TableCell(); mRow.Cells.Add(cellPickup); mRow.Cells.Add(cellName); mRow.Cells.Add(cellCode); ContainerTable.Rows.Add(mRow); LinkButton hrefName = new LinkButton(); hrefName.Text = mParts.Get(i).name; hrefName.Attributes["record_id"] = mParts.Get(i).id.ToString(); LinkButton hrefCode = new LinkButton(); hrefCode.Text = mParts.Get(i).code; hrefCode.Attributes["record_id"] = mParts.Get(i).id.ToString(); ImageButton mPickupButton = new ImageButton(); mPickupButton.BorderWidth = 0; mPickupButton.ImageUrl = "../Resources/pickup.gif"; mPickupButton.Attributes["record_id"] = mParts.Get(i).id.ToString(); cellPickup.Controls.Add(mPickupButton); cellName.Controls.Add(hrefName); cellCode.Controls.Add(hrefCode); mPickupButton.Click += new ImageClickEventHandler(mPickupButton_Click); hrefCode.Click += new EventHandler(hrefCode_Click); hrefName.Click += new EventHandler(hrefName_Click); cellPickup.Attributes["width"] = "1%"; cellCode.Attributes["width"] = "30%"; } } but Click events does not work until I add Load() method to PageLoad or LoadViewState. But then some of table rows are still from first page load, I try to clear them, but it does`nt help. What simple framework or principle should I use 1)to get work simple onevent -> 2)add dynamic elements with their events -> 3)use dynamically added control events?

      M Offline
      M Offline
      M LN Rao
      wrote on last edited by
      #2

      Can you tell me what is the problem, without elaboration.

      O 1 Reply Last reply
      0
      • M M LN Rao

        Can you tell me what is the problem, without elaboration.

        O Offline
        O Offline
        Oskars
        wrote on last edited by
        #3

        The problem is, that everything show up good, but click events does`nt work. When I click on dynamically added hyperlinks, hyperlink click event does`nt run, but page reloads and everything is gone.

        M 1 Reply Last reply
        0
        • O Oskars

          The problem is, that everything show up good, but click events does`nt work. When I click on dynamically added hyperlinks, hyperlink click event does`nt run, but page reloads and everything is gone.

          M Offline
          M Offline
          M LN Rao
          wrote on last edited by
          #4

          When you are adding controls dynamically to the page, you need to ensure the childcontrol exists on the other call. This you can do either by adding everytime when you call the page. protected void Page_Load(object sender, EventArgs e) { Load(); } then it works fine. let me know whether it works or not? I will on-line only.

          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