By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,320 Members | 2,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,320 IT Pros & Developers. It's quick & easy.

[C#-WEB] Trouble finding controls in Update panel

P: 6
Hi All,

I have a problem in finding control in a dynamically created updated panel. I have given the code below. Following is just a starting effort in a completely dynamic user control. I am experimenting before getting to the actual part. This is what I am trying to do:

* Create a tab container dynamically

* Create 5 tabs dynamically

* Add an update panel to each of the tabs

* Add a label to each of the update panels

* Add an OnLoad event to each of the tabs and change the contents of the label added

But I am not able to accomplish the last part, I am not sure how to access the label dynamically added to the update panel

I have given the code below. Please help me in this regard.


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using AjaxControlToolkit;
  14.  
  15. public partial class EvaluationsWidget : System.Web.UI.Page
  16. {
  17.    protected string[] tabnames = {"All","Contact Centers","Networks","Technology Planning"};
  18.  
  19.     protected Label lbl;
  20.  
  21.     protected void Page_Load(object sender, EventArgs e)
  22.      {
  23.           ArrayList al = new ArrayList();
  24.  
  25.           for (int i = 0; i < 20; i++)
  26.           al.Add(i.ToString());
  27.  
  28.           TabContainer tabContainer = new TabContainer();
  29.           tabContainer.ID = "tbContainerMain";
  30.           tabContainer.Width = 500;
  31.  
  32.           for (int i = 0; i < tabnames.Length; i++)
  33.           {
  34.               TabPanel tabPanel = new TabPanel();
  35.               tabPanel.ID = "evaluationsPanel" + i.ToString();
  36.               tabPanel.HeaderText = tabnames[i];
  37.               tabPanel.Load += new EventHandler(tabPanel_Load);
  38.  
  39.               UpdatePanel updPanel = new UpdatePanel();
  40.               updPanel.ID = "evaluationsUpdatePanel" + i.ToString();
  41.               updPanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
  42.  
  43.               lbl = new Label();
  44.               lbl.ID = "lbl" + i.ToString();
  45.               lbl.Text = "Label " + i.ToString();
  46.               updPanel.ContentTemplateContainer.Controls.Add(lbl);
  47.  
  48.               tabPanel.Controls.Add(updPanel);
  49.               tabContainer.Controls.Add(tabPanel);
  50.           }
  51.  
  52.           form1.Controls.Add(tabContainer);
  53.       }
  54.  
  55.       void tabPanel_Load(object sender, EventArgs e)
  56.       {
  57.           TabPanel tbPanel = (TabPanel)sender;
  58.  
  59.           //This doen't work, I need help here
  60.           this.lbl.Text = "Clicked";
  61.        }
  62.     }
  63.  


Thanks,

Karthik
Jul 31 '08 #1
Share this Question
Share on Google+
4 Replies


TTCEric
P: 26
You need a 'Handles TabControl.OnLoad' appended to the end of the function signature like this

private sub MyTabControl(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTabControl.OnLoad
Jul 31 '08 #2

P: 6
Hi Eric,

Thank you for your reply. What you've said is for VB. Net. I looked and found out that "handles" keyword and its functionality isn't available in C#. And I also found out that "AutoEventWireup" should be set to true in C# as "handles" cannot be used in C#.

I have set auto event wireup to true in my page, Still it doesn't work. Please note that the label is created dynamically and added to the update panel. How am I supposed to access that label in the update panel?

Thanks again for replying
Jul 31 '08 #3

TTCEric
P: 26
Oops. Didnt notice it was C#.

Ok, I found a link related to what you need. A good google keyword search is C# Event Handling. There are actually several ways to handle events in C#. This one I found most easier to follow:

http://www.c-sharpcorner.com/UploadF...ginCSharp.aspx
Jul 31 '08 #4

P: 6
Thanks a lot for your replies Eric. I was able to solve the problem! Thanks again!
Jul 31 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.