Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<asp:Table CssClass="table table-responsive" ID="tabl" runat="server"></asp:Table>


C#
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");

                //Typen CHeckBox eller TekstBox
                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;

                //Checkbox/Textbox tekst
                tblText = new TableCell();
                lblTekst = new Label();
                lblTekst.Text = txt;
                tblText.Attributes.Add("class", "col-md-3");
                tblText.Attributes.Add("style", "text-align:left;");
               
                //Prisen
                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;");

                //Tekst kr
                cellKr = new TableCell();
                lblKr = new Label();
                lblKr.Text = "&nbsp;&nbsp;&nbsp;&nbsp;kr";
                cellKr.Attributes.Add("class", "col-md-1");

                //true or false
                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;");
                

                //mine cells
                tblcellType.Controls.Add(textCHkBoxTextBox);
                tblTypeHidden.Controls.Add(hdnType);
                tblText.Controls.Add(lblTekst);
                tblcellPrice.Controls.Add(lblPrice);
                tblcellStatus.Controls.Add(lblStatus);
                
                cellKr.Controls.Add(lblKr);
             
                //mine ROWS
                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
Posted
Comments
Maciej Los 3-Mar-16 14:51pm    
Have you tried to debug the programme?
Martin Lauritsen 3-Mar-16 15:10pm    
if i set !ispostback on it says there multible objects with same id txt0, and if i remove !ispostback it create the xml file but its empty
Martin Lauritsen 3-Mar-16 15:10pm    
it creates the nodes but no data in it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900