Hi i have a big problem getting values from my danymaic control into an xml file.
my onclick button event can not fin the controls.
asp
<asp:Table CssClass="table table-responsive" ID="tabl" runat="server"></asp:Table>
C#
protected void Page_Load(object sender, EventArgs e)
{
CreateControls();
if (!IsPostBack)
{
CreateControls();
}
}
private void CreateControls()
{
string path = Server.MapPath("../xmlReDriverListToday/" + Request.QueryString["WebPrefix"] + Request.QueryString["UserName"] + "DriverSteps.xml");
XmlDocument xmlDokument = new XmlDocument();
xmlDokument.Load(path);
var nodeList = xmlDokument.SelectNodes("DriverStepChecks/StepChecks/Check");
TableRow tblrow;
TableCell tblTextCheckBox;
TableCell tblTypeHidden;
TableCell tblText;
TableCell tblcellPrice;
TableCell tblcellStatus;
TableCell tblcellType;
TableCell cellKr;
TextBox txtbx;
CheckBox chkbx;
HiddenField hdnType;
Label textCHkBoxTextBox;
Label lblTekst;
Label lblPrice;
HiddenField lblStatus;
Label lblKr;
for (int i = 0; i < nodeList.Count; i++)
{
XmlNode NodeR = nodeList[i];
string txt = NodeR["Text"].InnerText;
string txtPrice = NodeR["Price"].InnerText;
string txtType = NodeR["Type"].InnerText;
string status = NodeR["ReqCheck"].InnerText;
tblrow = new TableRow();
for (int j = 0; j < 1; j++)
{
tblTextCheckBox = new TableCell();
tblTextCheckBox.Attributes.Add("class", "col-md-1");
tblcellType = new TableCell();
textCHkBoxTextBox = new Label();
textCHkBoxTextBox.ID = "Type" + i;
textCHkBoxTextBox.Attributes.Add("style", "");
if (txtType.ToString() == "text")
{
textCHkBoxTextBox.Text = txtType;
txtbx = new TextBox();
txtbx.ID = "txt" + i;
txtbx.Attributes.Add("class", "form-control");
tblTextCheckBox.Controls.Add(txtbx);
}
else
{
textCHkBoxTextBox.Text = txtType;
chkbx = new CheckBox();
chkbx.ID = "txt" + i;
chkbx.Attributes.Add("class", "");
tblTextCheckBox.Controls.Add(chkbx);
}
tblTypeHidden = new TableCell();
hdnType = new HiddenField();
hdnType.Value = txtType;
hdnType.ID = "hdnType" + i;
tblText = new TableCell();
lblTekst = new Label();
lblTekst.Text = txt;
tblText.Attributes.Add("class", "col-md-3");
tblText.Attributes.Add("style", "text-align:left;");
tblcellPrice = new TableCell();
lblPrice = new Label();
lblPrice.Text = txtPrice;
lblPrice.Attributes.Add("style", "text-align:left;");
tblcellPrice.Attributes.Add("class", "col-md-1");
tblcellPrice.Attributes.Add("style", "text-align:right;");
cellKr = new TableCell();
lblKr = new Label();
lblKr.Text = " kr";
cellKr.Attributes.Add("class", "col-md-1");
tblcellStatus = new TableCell();
lblStatus = new HiddenField();
lblStatus.Value = status;
lblStatus.ID = "reqCheck" + i;
tblcellStatus.Attributes.Add("class", "col-md-3");
tblcellStatus.Attributes.Add("style", "text-align:left;");
tblcellType.Controls.Add(textCHkBoxTextBox);
tblTypeHidden.Controls.Add(hdnType);
tblText.Controls.Add(lblTekst);
tblcellPrice.Controls.Add(lblPrice);
tblcellStatus.Controls.Add(lblStatus);
cellKr.Controls.Add(lblKr);
tblrow.Cells.Add(tblTextCheckBox);
tblrow.Cells.Add(tblTypeHidden);
tblrow.Cells.Add(tblText);
tblrow.Cells.Add(tblcellPrice);
tblrow.Cells.Add(cellKr);
tblrow.Cells.Add(tblcellStatus);
}
tabl.Rows.Add(tblrow);
}
}
protected void btnChecks_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
XmlNode UpdateCheck = doc.CreateElement("DriverStepsUpdateRequest");
doc.AppendChild(UpdateCheck);
XmlNode RecordNode = doc.CreateElement("RecordType");
RecordNode.AppendChild(doc.CreateTextNode("DriverStepsUpdate"));
UpdateCheck.AppendChild(RecordNode);
XmlNode dateFormatNode = doc.CreateElement("DateFormat");
dateFormatNode.AppendChild(doc.CreateTextNode("DDMMYYYY"));
UpdateCheck.AppendChild(dateFormatNode);
XmlNode comNode = doc.CreateElement("WebPrefix");
comNode.AppendChild(doc.CreateTextNode(Request.QueryString["WebPrefix"]));
UpdateCheck.AppendChild(comNode);
XmlNode drivNode = doc.CreateElement("UserName");
drivNode.AppendChild(doc.CreateTextNode(Request.QueryString["UserName"]));
UpdateCheck.AppendChild(drivNode);
XmlNode StepType = doc.CreateElement("StepType");
StepType.AppendChild(doc.CreateTextNode(txtStepType.Text));
UpdateCheck.AppendChild(StepType);
XmlNode StepDate = doc.CreateElement("StepDate");
StepDate.AppendChild(doc.CreateTextNode(DateTime.Now.ToShortDateString()));
UpdateCheck.AppendChild(StepDate);
XmlNode StepTime = doc.CreateElement("StepTime");
StepTime.AppendChild(doc.CreateTextNode(DateTime.Now.ToShortTimeString()));
UpdateCheck.AppendChild(StepTime);
XmlNode stepChecksNode = doc.CreateElement("StepChecks");
UpdateCheck.AppendChild(stepChecksNode);
for (int i = 0; i < 100; i++)
{
TextBox txtInstance = (TextBox)FindControl("txt" + i);
string textbox = txtInstance.Text;
string txtType = Request.Form["Type" + i];
string hdnType = Request.Form["hdnType" + i];
string reqCheck = Request.Form["reqCheck" + i];
XmlNode checkNode = doc.CreateElement("Check");
stepChecksNode.AppendChild(checkNode);
XmlNode roomTy = doc.CreateElement("Text");
roomTy.AppendChild(doc.CreateTextNode(txtType));
checkNode.AppendChild(roomTy);
XmlNode typeNode = doc.CreateElement("Type");
typeNode.AppendChild(doc.CreateTextNode(hdnType));
checkNode.AppendChild(typeNode);
XmlNode priceNode = doc.CreateElement("Price");
priceNode.AppendChild(doc.CreateTextNode(txtType));
checkNode.AppendChild(typeNode);
XmlNode reqCheckNode = doc.CreateElement("ReqCheck");
reqCheckNode.AppendChild(doc.CreateTextNode(textbox.ToString()));
checkNode.AppendChild(reqCheckNode);
}
doc.Save(Server.MapPath("../xmlReDriverListToday/" + Request.QueryString["WebPrefix"] + Request.QueryString["UserName"] + "DriverStepChecks.xml"));
What I have tried:
A lot createde the things from the beginnig because i have another site they are working on