Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ResetEmpNominee();
}
if (Convert.ToInt32(ddlEmployee.SelectedValue) > 0)
{
populateTrainingInfo(Convert.ToInt16(ddlEmployee.SelectedValue));
}
}
protected void btnTrainingSave_Click(object sender, EventArgs e)
{
try
{
short empID = 0;
if (empID =0)
{
success = hrServer.addToEmpTraining(trainingNew, path);
if (success.Equals("Success"))
{
Msg = "Successfully Added..."; }
else
{
Msg = success;
}
}
else
{
}
WebUtil.jsCall("alert('" + Msg + "')", this);
Page_Load(null, null);
}
catch (Exception ex)
{
WebUtil.MessageBox_Show(ex.Message, this);
}
}
private void populateTrainingInfo(short empID)
{
HumanResourceServer hrServer = new HumanResourceServer();
DataSet trainingInfoes = hrServer.GetEmployeeTrainingInfo(empID);
int i = 0;
int count = trainingInfoes.Tables[0].Rows.Count;
ViewState["TrainingInfo"] = trainingInfoes.Tables[0];
int k = 0;
DataTable dtTraining = trainingInfoes.Tables[0];
for (i = 0; i < dtTraining.Rows.Count; i++)
{
//first row
Table tblTraining = new Table();
tblTraining.Width = 900;
TableCell tcLeft1 = new TableCell();
TableCell tcRight1 = new TableCell();
TableRow tr1 = new TableRow();
tr1.CssClass = "cvItemSubHeader";
Label lblHeader1 = new Label();
lblHeader1.ID = "Training" + Convert.ToString(i + 1);
lblHeader1.Text = "Training :" + Convert.ToString(i + 1);
tcLeft1.CssClass = "cvColumnCaption";
//tcLeft1.CssClass = "cvItemButtonCell";
tcLeft1.Controls.Add(lblHeader1);
tcLeft1.HorizontalAlign = HorizontalAlign.Left;
Button btnTrainingEdit = new Button();
btnTrainingEdit.ID = "btnTrainingEdit" + Convert.ToString(i + 1);
btnTrainingEdit.Text = "Edit";
btnTrainingEdit.CssClass = "DSEButton4";
//Label lblHeader2 = new Label();
//lblHeader2.ID = "LevelofEducationData" + Convert.ToString(i);
//lblHeader2.Text = dtTraining.Rows[i]["EDUCATIONLEVELNAME"].ToString();
tcRight1.HorizontalAlign = HorizontalAlign.Right;
//tcRight1.Style["Padding-left"] ="50";
tcRight1.CssClass = "cvItemButtonCell";
tcRight1.Controls.Add(btnTrainingEdit);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
btnTrainingEdit.Click += new System.EventHandler(btnTrainingEdit_click);
tcRight1.Controls.Add(btnTrainingEdit);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
//hidden row for educationid
tcLeft1 = new TableCell();
tcRight1 = new TableCell();
tr1 = new TableRow();
tr1.CssClass = "hiddenDynamicRows";
lblHeader1 = new Label();
lblHeader1.ID = "TRAININGID" + Convert.ToString(i + 1);
lblHeader1.Text = "TRAININGID";
tcLeft1.CssClass = "cvColumnCaption";
tcLeft1.Controls.Add(lblHeader1);
tcLeft1.HorizontalAlign = HorizontalAlign.Left;
Label lblHeader2 = new Label();
lblHeader2.ID = "TRAININGIDData" + Convert.ToString(i + 1);
lblHeader2.Text = dtTraining.Rows[i]["TRAININGID"].ToString();
tcRight1.Controls.Add(lblHeader2);
tr1.Cells.Add(tcLeft1);
tr1.Cells.Add(tcRight1);
tblTraining.Rows.Add(tr1);
Trainings.Controls.Add(tblTraining);
}
count = trainingInfoes.Tables[0].Rows.Count;
}
aspx page contain some following code
<table class="contentRow" width="900px">
<tr class="cvItemHeader" align="left">
<td align="left" >
<div><div class="cvItemHeaderText"> Training Summary </div>
<div class="cvItemHeaderButton">
<asp:Button ID="btnAddTraining" runat="server" CssClass="DSEButton4"
Text="Add" onclick="btnAddTrainingInfo_Click" /> </div>
</div>
</td>
</tr>
<div id="Trainings" runat="server"></div>
</table>
Sorry, for my unclear question. btnTrainingSave_Click method save data into database. I need to update the div with id='Trainings' after saving the data into database. I called page_load method at the end of btnTrainingSave_Click method. But it does not work. can anybody help me how can I do that? Perhaps this time my question is clear.
the concept is wrong, to refresh the page redirect to the same URL
Page.Response.Redirect(Page.Request.Url.ToString(), true);
Related
I want the checkbox control to be added dynamically with different id's in different th tags generating in a loop
<table border="1">
<thead>
<%string j = " Check"; %>
<%for (int i = 0; i < 10;i++ )
{%>
<th style="padding:2px; width:500px;">Table Head<br /><br />
<%
CheckBox chk = new CheckBox();
chk.ID = i + j;
chk.Text = "I am " + i + j;
%>
//I want this checkbox to be added dynamically here with different id's in different th tags generating in a loop
<asp:CheckBox runat="server" ID="<%=i+j%>"/>
</th>
<%} %>
</thead>
</table>
the way to do this is to create yourself a server-control with all the parameters you need, creating the controls in the OnInit, and rendering html in the RenderControl, and accessing the controls from public props like this:
public class DynamicCbs : Control
{
public int CtrlsCount { get; set; }
public List<CheckBox> lstCheckBoxs;
/// decleration of controls must be in the OnInit since the next stage of the page life cycle is to connect whatever came back from the client to the server
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
lstCheckBoxs = new List<CheckBox>();
for (int i = 0; i < CtrlsCount; i++)
{
string id = "DynamicCbs" + i;
CheckBox cbx = new CheckBox()
{
ID = id,
Text = "i am " + id
};
lstCheckBoxs.Add(cbx);
//add controls to control tree
this.Controls.Add(cbx);
}
}
/// here you must build ur html
public override void RenderControl(HtmlTextWriter writer)
{
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Thead);
foreach (var cbx in lstCheckBoxs)
{
writer.RenderBeginTag(HtmlTextWriterTag.Th);
cbx.RenderControl(writer);
writer.RenderEndTag();
}
writer.RenderEndTag();//thead
writer.RenderEndTag();//table
}
}
full example
ok I found the solution. I have use asp:Table control to solve this problem
My aspx page code is :
<asp:Table ID="ObjectwiseTable2" runat="server"
CssClass="AccessTable" BorderColor="Black" width="100%">
</asp:Table>
My .cs page code to Add content and dynamic content in the table is :
TableHeaderRow thead = new TableHeaderRow();
TableHeaderCell th = new TableHeaderCell();
th.Controls.Add(new LiteralControl("Object Wise Detail(s)"));
th.RowSpan = 2;
thead.Cells.Add(th);
int totalUsers = accesswiseDt.Rows.Count;
for (int User = 0; User < totalUsers; User++)
{
TableHeaderCell th2 = new TableHeaderCell();
th2.Controls.Add(new LiteralControl(accesswiseDt.Rows[User]["users"].ToString()));
IsReviewPending = view_access.IsWaitingForViewAccess(ApplicationTree.SelectedNode.Value, Session["empCode"].ToString(), accesswiseDt.Rows[User]["empcode"].ToString());
if (IsReviewPending)
{
th2.Controls.Add(new LiteralControl("<br />"));
CanReviewAccess = true;
//Code for Adding Dynamic control in specific cell of the table
CheckBox chk = new CheckBox();
chk.ID = ApplicationTree.SelectedNode.Value + "_" + accesswiseDt.Rows[User]["empcode"].ToString();
chk.Text = "Access Reviewed";
th2.Controls.Add(chk);
}
thead.Cells.Add(th2);
}
In my ASP.Net page I need to show an HTML div who contains : Images, Text, Arrows and Connectors.
What are my "Connectors" ?
It's an ImageButton, and when the user click on this connector, the HTML div is showing a new content. This connectors are used to navigate in a TreeView.
But my problem is :
I create all my connectors (and all the HTML div content) dynamically. When the user click on the first connector the HTML div is showing new content. But on this second content, when the user click on a connector : nothing. The Click event of the ImageButton is not fired.
This is my Connector creation (on PageLoad and then on each Connector Click) :
List<Connecteur> ListConnecteur = new List<Connecteur>();
ListConnecteur = NomenclatureObj.SelectConnecteurs(DocId, ExterneData.RapidoBDDCnx);
foreach (Connecteur CeConnecteur in ListConnecteur)
{
if (CeConnecteur.FK_docversion_suivant_id != 0)
{
ImageButton ImgBtnTmp = new ImageButton();
ImgBtnTmp.Width = 30;
ImgBtnTmp.Height = 30;
ImgBtnTmp.ImageUrl = "~/images/GreenButton.png";
ImgBtnTmp.Style.Add("left", CeConnecteur.position_x_pix.ToString() + "px");
ImgBtnTmp.Style.Add("top", CeConnecteur.position_y_pix.ToString() + "px");
ImgBtnTmp.Click += new ImageClickEventHandler(ImgBtnTmp_Click);
ImgBtnTmp.CommandArgument = CeConnecteur.FK_docversion_suivant_id.ToString();
ImgBtnTmp.Style.Add("position", "absolute");
DivAffichage.Controls.Add(ImgBtnTmp);
ImgBtnTmp.CausesValidation = true;
}
}
And this is my Connector OnClick :
public void ImgBtnTmp_Click(object sender, EventArgs e)
{
ImageButton ThisBtn = sender as ImageButton;
string CommandArg = ThisBtn.CommandArgument;
int DocId = Convert.ToInt32(CommandArg);
TREEVIEW_NIVEAU++;
//DocId of the clicked connector
Session["DocId"] = DocId;
ClearDiv();
LoadDiv(DocId);
}
EDIT 1 : My whole LoadDiv() function
public void LoadDiv(int DocId)
{
#region Connecteurs
List<Connecteur> ListConnecteur = new List<Connecteur>();
ListConnecteur = NomenclatureObj.SelectConnecteurs(DocId, ExterneData.RapidoBDDCnx);
foreach (Connecteur CeConnecteur in ListConnecteur)
{
if (CeConnecteur.FK_docversion_suivant_id != 0)
{
ImageButton ImgBtnTmp = new ImageButton();
ImgBtnTmp.Width = 30;
ImgBtnTmp.Height = 30;
ImgBtnTmp.ImageUrl = "~/images/GreenButton.png";
ImgBtnTmp.Style.Add("left", CeConnecteur.position_x_pix.ToString() + "px");
ImgBtnTmp.Style.Add("top", CeConnecteur.position_y_pix.ToString() + "px");
ImgBtnTmp.Click += new ImageClickEventHandler(ImgBtnTmp_Click);
ImgBtnTmp.CommandArgument = CeConnecteur.FK_docversion_suivant_id.ToString();
ImgBtnTmp.Style.Add("position", "absolute");
DivAffichage.Controls.Add(ImgBtnTmp);
}
}
#endregion
#region Textes
List<Texte> ListTexte = new List<Texte>();
ListTexte = NomenclatureObj.SelectTextes(DocId, LANGUE_ID, ExterneData.RapidoBDDCnx);
foreach (Texte CeTexte in ListTexte)
{
Label LblText = new Label();
LblText.Text = CeTexte.contenu;
LblText.Width = CeTexte.largeur_voulue_pix;
LblText.Style.Add("left", CeTexte.position_x_pix.ToString() + "px");
LblText.Style.Add("top", CeTexte.position_y_pix.ToString() + "px");
LblText.Style.Add("position", "absolute");
DivAffichage.Controls.Add(LblText);
}
#endregion
#region Images
List<ImageNomenclature> ListImg = new List<ImageNomenclature>();
ListImg = NomenclatureObj.SelectImages(DocId, ExterneData.RapidoBDDCnx);
foreach (ImageNomenclature CetteImage in ListImg)
{
Image ImgTmp = new Image();
ImgTmp.ImageUrl = "~/Nomenclature/RAPIDO/planches/" + CetteImage.fichier_chemin;
ImgTmp.Width = CetteImage.largeur_voulue_pix;
ImgTmp.Height = CetteImage.hauteur_voulue_pix;
ImgTmp.Style.Add("left", CetteImage.position_x_pix.ToString() + "px");
ImgTmp.Style.Add("top", CetteImage.position_y_pix.ToString() + "px");
ImgTmp.Style.Add("position", "absolute");
ImgTmp.Style.Add("z-index", "-1");
DivAffichage.Controls.Add(ImgTmp);
}
#endregion
#region Flèches
List<Fleche> ListFleche = new List<Fleche>();
ListFleche = NomenclatureObj.SelectFleches(DocId, LANGUE_ID, ExterneData.RapidoBDDCnx);
foreach (Fleche CetteFleche in ListFleche)
{
string HTMLCode = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"800\" height=\"600\"><line x1=\"" + CetteFleche.position_x1_pix + "\" y1=\"" + CetteFleche.position_y1_pix + "\" x2=\"" + CetteFleche.position_x2_pix + "\" y2=\"" + CetteFleche.position_y2_pix + "\" stroke=\"#ff0000\"/></svg>";
//DivAffichage.InnerHtml += HTMLCode;
}
#endregion
}
You should create your dynamic control every time on Page_Init or Page_Load if you would like to handle events from them after Postback.
See links below for details:
http://msdn.microsoft.com/en-us/library/y3bwdsh3%28v=vs.140%29.aspx
http://msdn.microsoft.com/en-us/library/hbdfdyh7%28v=vs.100%29.aspx
Here you can see the same problem.
EDIT
Try to do something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
LoadDiv(Session["DocId"])
}
}
i'm in a trouble!
I'm generating a lot of gridviews dinamically, with dinamic values to columns.
The columns are ever the same.
I want to know how can i set the size of this columns.
That's my code, with my effort.
private void generateControls( List<List<DataRow>> grids)
{
DataTable dt = new DataTable();
int i = 0;
foreach (List<DataRow> lst in grids)
{
dt = lst.CopyToDataTable();
GridView grv = new GridView();
grv.AlternatingRowStyle.BackColor = System.Drawing.Color.FromName("#cccccc");
grv.HeaderStyle.BackColor = System.Drawing.Color.Gray;
grv.Width = new Unit("100%");
//grv.RowStyle.Wrap = false;
grv.RowStyle.Width = new Unit("100%");
grv.ID = "grid_view" + i;
grv.DataSource = dt;
grv.DataBind();
/* grv.Columns[0].ItemStyle.Width = new Unit("5%");
grv.Columns[1].ItemStyle.Width = new Unit("7%");
grv.Columns[2].ItemStyle.Width = new Unit("12%");
grv.Columns[3].ItemStyle.Width = new Unit("12%");
grv.Columns[4].ItemStyle.Width = new Unit("7%");
grv.Columns[5].ItemStyle.Width = new Unit("7%");
grv.Columns[6].ItemStyle.Width = new Unit("23%");
grv.Columns[7].ItemStyle.Width = new Unit("22%");
grv.Columns[8].ItemStyle.Width = new Unit("5%");*/
Label lblBlankLines = new Label();
lblBlankLines.Text = "<br />";
Panel panelGrid = new Panel();
panelGrid.ID = "panel_grid" + i;
Label lblTipo = new Label();
string tipoOcorrencia = lst[0]["Ocorrência"].ToString();
/*
* Capitalized
* TextInfo myTI = new CultureInfo("pt-BR", false).TextInfo;
string novoTipoOcorrencia = myTI.ToTitleCase(tipoOcorrencia);*/
int quantidade = lst.Count;
lblTipo.Text = " - " + tipoOcorrencia + ": " + quantidade;
LinkButton lkBtn = new LinkButton();
lkBtn.ID = "link_button" + i;
lkBtn.Text = "Exibir | Ocultar";
lkBtn.Attributes["onClick"] = "javascript:return ocultaGrid('" + panelGrid.ID + "'), false";
panel_status.Controls.Add(lblBlankLines);
panel_status.Controls.Add(lkBtn);
panel_status.Controls.Add(lblTipo);
panelGrid.Controls.Add(grv);
panel_status.Controls.Add(panelGrid);
panel_status.DataBind();
i++;
}
}
I've tried to get the columns, but i got an error, telling me an invalid index access.
How can i access my columns in that gridview?
Use the RowDataBound EventHandler:
Count your indexes and make sure you are not trying to access a non-existent column as well.
See link for an example:
http://msdn.microsoft.com/en-us/library/ms178296(v=vs.100).ASPX
grv.RowDataBound += grv_RowDataBound;
private void grv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Width = new Unit("5%");
e.Row.Cells[1].Width = new Unit("7%");
e.Row.Cells[2].Width = new Unit("12%");
e.Row.Cells[3].Width = new Unit("12%");
e.Row.Cells[4].Width = new Unit("7%");
e.Row.Cells[5].Width = new Unit("7%");
e.Row.Cells[6].Width = new Unit("23%");
e.Row.Cells[7].Width = new Unit("22%");
e.Row.Cells[8].Width = new Unit("5%");
}
}
I created a button that is supposed to view a message in a updatepanel.
I dynamically added through code since the ammount of buttons are relative to how many messages they recieve. I need the button to display a label. Any Ideas?
Here is my code:
I feel like the problem that the scope is limited to the loop. I was going to change the id to increase "lblbody" = 1+=1
$ while (reader.Read())
{
string strrecipient, strsender, strsubject, strbody, strdate, strviewstate;
strdate = "Date Sent: " + reader["date"].ToString();
strsender = "From: " + reader["sender"].ToString();
strsubject = "Subject: " + reader["subject"].ToString();
strbody = reader["body"].ToString();
strrecipient = "To: " + reader["recipient"].ToString();
if (reader["viewstate"].ToString() == "notread")
{
strviewstate = "UnRead";
}
else
{
strviewstate = "read";
}
string strName;
int intName;
intName = 0;
strName = intName.ToString();
Panel pnlNewMess = new Panel();
pnlMess.Controls.Add(pnlNewMess);
pnlNewMess.BorderColor = System.Drawing.Color.LightGray;
pnlNewMess.BorderStyle = BorderStyle.Solid;
pnlNewMess.BorderWidth = 1;
Label lbldate = new Label();
Label lblsender = new Label();
Label lblsubject = new Label();
Label lblbody = new Label();
Label lblrecipient = new Label();
Label lblviewstate = new Label();
Button btnView = new Button();
lbldate.Text = strdate;
lblsender.Text = strsender;
lblsubject.Text = strsubject;
lblbody.Text = strbody;
lblrecipient.Text = strrecipient;
lblviewstate.Text = strviewstate;
btnView.Text = "View Message";
btnView.ID = strsubject;
lblbody.Visible = false;
lblrecipient.Visible = false;
lblviewstate.Visible = false;
//lblbody.ID = "lblBody" + strName;
pnlNewMess.Controls.Add(lblrecipient);
pnlNewMess.Controls.Add(new LiteralControl("<br />"));
if (lblviewstate.Text == "notread")
{
pnlNewMess.Controls.Add(new LiteralControl("<div class='clsmess' style='background-image:url('images/unread.png'); color:white;'>"));
}
else
{
pnlNewMess.Controls.Add(new LiteralControl("<div class='clsmess' style='background-image:url('images/read.png'); color:white;'>"));
}
pnlNewMess.Controls.Add(lbldate);
pnlNewMess.Controls.Add(lblsubject);
pnlNewMess.Controls.Add(lblsender);
pnlNewMess.Controls.Add(btnView);
pnlNewMess.Controls.Add(new LiteralControl("</div>"));
pnlNewMess.Controls.Add(lblviewstate);
pnlNewMess.Controls.Add(new LiteralControl("<br />"));
pnlView.Controls.Add(lblbody);
pnlMess.Controls.Add(pnlNewMess);
}
The only thing I have tried was to set a click event for the button taking the subject lbl.text to a global variabe and then with the click of another button, would compare the subject field with the database and display the lblbody.
btnview.text = lblsubject.text;
SqlCommand CMretMess = new SqlCommand("SELECT body FROM [message] WHERE subject='" + clsGlobals.myGlobals.strSub + "'", connection);
lblBody.Text = CMretMess.ExecuteScalar().ToString();
connection.Close();
Could you do something as simple as this?
btnView.Click += (sender, e) => {
lblbody.Visible = true;
};
The problem is: On postback, the table does not have the rows that were dynamically created, the rowcount is 0.
Click on the button, it should detect the checked checkboxes within the table dynamically generated.
The table is made by code when the "day" is selected using the drop down list and "the starting date" is selected using the calender.
I know there's a lot of code, but it's the least I thought I had to post, so answerers can debug. Please note I have tried hard but cannot get the solution to this.
Here’s the code:
public partial class DaySelection : System.Web.UI.Page
{
Table table1 = new Table();
Button button1 = new Button();
string the_id_checkbox;
string the_id_label;
//The need of the table ENDS
DropDownList selectdays = new DropDownList();
Label theselecteddate = new Label();
Button extract_the_selected = new Button();
Literal selected_values=new Literal();
int number_of_row = -1;
protected void Page_Load(object sender, EventArgs e)
{
CheckBox check_or_not = new CheckBox();
try
{
selected_values.Text = "";
form1.Controls.Remove(selected_values);
form1.Page.Response.Write("inside try");
for (int i = 0; i < table1.Rows.Count; i++)
{
Response.Write("inside for");
the_id_checkbox = "checkmate" + i;
the_id_label = "The_text" + i;
check_or_not = (CheckBox)table1.Rows[i].FindControl(the_id_checkbox);
if (check_or_not.Checked == true)
{
form1.Page.Response.Write("inside if");
selected_values.Text = selected_values.Text + "<br /> " + check_or_not.Checked.ToString();
selected_values.Text = selected_values.Text + " and the day is: " + ((Label)table1.Rows[i].FindControl(the_id_label)).Text;
}
else
{
Response.Write(" selection no detect");
}
}
form1.Controls.AddAt(1, selected_values);
Response.Write(selected_values.Text);
}
catch (NullReferenceException nn)
{
form1.Page.Response.Write("inside catch" + nn.Message.ToString() + nn.StackTrace);
}
extract_the_selected.Text = "Extract it";
form1.Controls.AddAt(2,extract_the_selected);
selectdays.AutoPostBack = true;
ArrayList thedays = new ArrayList();
thedays.Add("Monday" + DateTime.Now);
thedays.Add("Tuesday");
thedays.Add("Wednesday");
thedays.Add("Thursday");
thedays.Add("Friday");
thedays.Add("Saturday");
thedays.Add("Sunday");
selectdays.DataSource = thedays;
selectdays.DataBind();
form1.Controls.AddAt(3,selectdays);
Calendar1.SelectionChanged += new EventHandler(Calendar1_SelectionChanged);
}
void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DateTime startdate;
string month;
month = Calendar1.SelectMonthText;
startdate = Calendar1.SelectedDate;
days_date(startdate);
}
void selectdays_SelectedIndexChanged(object sender, EventArgs e)
{
display_dates_of_day(DateTime.Parse("9-1-2010"), DateTime.Parse("9-30-2010"), selectdays.SelectedItem.Text);
}
public void days_date(DateTime startdate)
{
int noofdays;
DateTime enddate = new DateTime();
noofdays = DateTime.DaysInMonth(startdate.Year, startdate.Month) - 1;
enddate = startdate.AddDays(noofdays);
Response.Write("<br /> end date is " + enddate);
Response.Write("<br /> start date is " + startdate);
display_dates_of_day( startdate, enddate, selectdays.SelectedItem.Text);
}
void display_dates_of_day(DateTime startDate, DateTime endDate, string selectedday)
{
int Count = 0;
for (DateTime dt = startDate; dt <= endDate; dt = dt.AddDays(1.0))
{
if (dt.DayOfWeek.ToString() == selectedday)
{
table1.ID = "table1";
number_of_row = number_of_row + 1;
string date = dt.Date.ToString("dd-MMMM-yyyy");
for (int adding_rows = 0; adding_rows < 1; adding_rows++)
{
TableRow table_row1 = new TableRow();
TableCell table_cell1 = new TableCell();
TableCell table_cell2 = new TableCell();
Label The_label = new Label();
CheckBox checkmate = new CheckBox();
The_label.Text = date + " (<---date)" + number_of_row;
the_id_checkbox = "checkmate" + number_of_row;
checkmate.ID = the_id_checkbox;
the_id_label = "The_text" + number_of_row;
The_label.ID = the_id_label;
table_cell2.Controls.Add(checkmate);
table_cell1.Controls.Add(The_label);
table_row1.Controls.AddAt(0, table_cell1);
table_row1.Controls.AddAt(1, table_cell2);
table1.Rows.Add(table_row1);
}
button1.Text = "click me to export the value";
form1.Controls.Add(table1);
form1.Controls.AddAt(1, selected_values);
Count++;
}
}
Response.Write("<br /> The count of days by traversing: " + Count);
}
}
The reason you're seeing this seemingly "strange" behaviour is that you're dynamically constructing the contents of Table1 and adding it to the pages .Controls collection only in the display_dates_of_day method, which is called by:
selectdays_SelectedIndexChanged
Calendar1_SelectionChanged (indirectly)
This means that when your page is re-contructed on post-back, the controls don't exist. If you "View Source" in your browser, you'll find that after clicking the button to trigger a post-back you can't find the string "Table1" in the markup, but if you do it after clicking on a date in the calendar, you can. That's because in the "clicking the button" scenario, the control is never populated and added to the page
I'd make a few suggestions to get your head round this and solve the problem:
Start with a much simplified version of this to help you understand the asp.net page lifecycle and how it impacts on what you're doing.
Try to ensure your code adds as few controls as possible to the page dynamically as this makes things a lot simpler. i.e. Make Table1 a control that's declared in the .aspx page.