Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with retreiving text data with concatenate method

Hello,

I've made some progress with the code below, but I'm running into two issuse.

1. The value retrieved from the controls is for example c1Receiver.text insatead of the actual values displayed

2. The prgram only saves data to the last xml file in the string (i.e. Receiver.xml), but I need to save the text values of the controls to all the xml files that are part of curXYZ.

How do I solve those two issues?  
Dim xyz() As String = New String() {"Manufacturer", "Receiver"}
        Dim i As Integer
        i = 0
        For i = 0 To 1
            Dim curXYZ = xyz(i)
            Dim MyFix As XDocument = XDocument.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim xid As String
            xid = curXYZ & "_ID"
            Dim LargestFixID = (From el In MyFix.Descendants(curXYZ & "Table") Select CInt(el.<xid>.Value)).ToList
            LargestFixID.Sort()
            Dim xtable As String
            xtable = curXYZ & "Table"
            Dim xcontrol1 As String
            xcontrol1 = "Me.C1" & curXYZ & ".Text"
            Dim xcontrol As String
            xcontrol = "Me.C1" & curXYZ & ".Text.ToString"

            Dim CheckForItemFix = (From el In MyFix.Descendants(xtable).Elements(curXYZ) Select el.Value).ToList
            If Not CheckForItemFix.Contains(xcontrol1) Then
                Dim xNew As XElement = New XElement(xtable)
                xNew.Add(New XElement(xid, (LargestFixID.Last() + 1)))
                xNew.Add(New XElement(curXYZ, xcontrol1))
                MyFix.Root.Add(xNew)
                MyFix.Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            End If

            Dim searchFix As String = xcontrol1
            Dim searchIdFix As String = Nothing
            Dim domFix As New XmlDocument()
            domFix.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim listFix As XmlNodeList = domFix.SelectNodes("//" & xtable)
            If CheckForItemFix.Contains(xcontrol1) Then
                For Each node As XmlNode In listFix
                    If node(curXYZ).InnerText.Equals(searchFix) Then
                        searchIdFix = node(xid).InnerText
                        Exit For
                    End If
                Next
            End If
        Next

Open in new window


Thanks,

Victor
Avatar of djon2003
djon2003
Flag of Canada image

Using xcontrol1 = "Me.C1" & curXYZ & ".Text" you are creating the string :
Me.C1Manufacturer.Text
and not getting the text of this control.
for that, use :
Me.Controls("C1" & curXYZ).Text
Avatar of Victor  Charles

ASKER

Thanks for the code , do you have a suggestion to solve the second issue?

I would like to avoid writing a separate If statement for MyFix for each value of curXYZ

 If Not CheckForItemFix.Contains(xcontrol1) Then
                Dim xNew As XElement = New XElement(xtable)
                xNew.Add(New XElement(xid, (LargestFixID.Last() + 1)))
                xNew.Add(New XElement(curXYZ, xcontrol1))
                MyFix.Root.Add(xNew)
                MyFix.Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            End If

Do another For surrounding this code which creates a new curXYZ2 so that both can be used if necessary, but certainly to not interfere between each other.
Hello,

When I try  Me.Controls("C1" & curXYZ).Text

I receive the following error: "Text is not a member of  'System.Web.UI.Control"

Victor
Oh yes ! I shall have seen it from the instruction Server.MapPath that your are writing an ASP.NET page in VB.NET. Just a hint, when you post a question in this condition, you shall put both tags for the question (easy for experts to get).

So next, Text property doesn't exist in the class System.Web.UI.Control. What is the type of control you are accessing ? If they are all of the same type and this type has a Text property, then you can cast to your control type.

CType(Me.Controls("C1" & curXYZ), !!!MYTYPE!!!).Text

You have to replace !!!MYTYPE!!! with the real type of the control you use.

If your control doesn't have the Text property, then you should access the appropriate property to get what you need.


Looking into MSDN or Object browsers (into Visual Studio), you can know all the members (properties, methods, events, etc) of any class you need.
Hello,

Yes it does have a text property, I am using a control from ComponentOne. The properties windows shows the following:

 C1Receiver C1.Web.UI.Controls.C1ComboBox.C1ComboBox.

Should the code be CType(Me.Controls("C1" & curXYZ), C1ComboBox.C1ComboBox).Text

Thanks,

Victor

Shall be
Hi,

I received the following error:

Conversion from string "C1Manufacturer" to type 'Integer' is not valid.
 with code:

Dim xcontrol1 As String
xcontrol1 = CType(Me.Controls("C1" & curXYZ), C1ComboBox).Text

Same error occured with

 Dim xcontrol1 As String
 xcontrol1 = CType(Me.Controls("C1" & curXYZ), C1ComboBox.C1ComboBox).Text


Victor

Ok. I'll give you directly the solution, but I really think you should read the MSDN to at least understand the classes you're using. I'll give you an example.

In the instruction : CType(Me.Controls("C1" & curXYZ), C1ComboBox).Text

Me refers to a System.Web.UI.Page class. (Supposed here, but quiet sure due to the error message you gave me)
Controls refers to a System.Web.UI.ControlCollection class.
(...) refers to the property Item of the ControlCollection class returned by the Controls property of the Page class.
In fact, it is : CType(Me.Controls.Item("C1" & curXYZ), C1ComboBox).Text

All the classes named here could be found into MSDN using google or within search engine. You can scan all the properties and their description just to learn the possibilities offered by these classes. Making that, you won't remember all of that, but at least some and more, you're comprehension of all this will grow up.

So, here, your bug occurs because the Item property requires one parameter which is an Integer. As specified in the message error. So now, we understand that accessing the control by the ID (here I presume that "C1" & curXYZ is the ID) can't be done with this property.

Looking around, you would found a method on Control class called FindControl which allows you to search by ID a control. So the instruction would become :
CType(Me.FindControl("C1" & curXYZ), C1ComboBox).Text

------

I always promote experience learning which makes your knowledge growing, but also your competency to reach information and others aside.
Thank you, I will try it and get back to you.
Hi,

I tried it but received the folowig error: Object reference not set to an instance of an object.

I am not trying the retreive the ID,  the xcontrol1 should return the text values of the combobos controls.
Below is a part of the code curXYZ based on the value I received for xtable, curXYZ is returning the correct data (i.e. ReceiverTable)

            Dim xtable As String
            xtable = curXYZ & "Table"
            Dim xcontrol1 As String
            MsgBox(xtable)
            xcontrol1 = CType(Me.FindControl("C1" & curXYZ), C1ComboBox).Text ***Error line
            MsgBox(xcontrol1)

Thanks

Victor



I'm missing information to continue. Can I see the ASP.NET page ? How to you define the controls you try to access ?

How long have you been programming ?
Hi,

I've been programming windows applications for long time, but mainly using SQL statements with crystal Report, recently started using LINQ and XM.

Below is my code:

Thanks,


Code ASPX:

<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="AOP28Web090811._Default" %>

<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1GridView" tagprefix="cc1" %>

<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1ComboBox" tagprefix="cc2" %>

<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1Input" tagprefix="cc3" %>
<%@ Register assembly="C1.Web.UI.Controls.4" namespace="C1.Web.UI.Controls.C1Calendar" tagprefix="cc4" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <style type="text/css">
    </style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <h2 class="style177">
        <strong>[Add] screen</strong></h2>
    <p class="style3">
        <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
            <asp:View ID="View1" runat="server">
            <table class="style1">
                    <tr>
                        <td class="style216" colspan="10">
                            <strong>Basic Item Data</strong></td>
                    </tr>
                    <tr>
                        <td class="style226">
                            100-Item Desigation</td>
                        <td class="style180">
                            <cc2:C1ComboBox ID="C1Item" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" DropDownPositioningMode="RightTop"
                                EmptyText="" FooterText=""  
                                ToolTip="Enter or Select Existing Item" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista" Height="21px" Width="162px" Text="Enter/Select">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style209">
                            <asp:Button ID="Button10" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                        <td class="style209" colspan="2">
                            <asp:Button ID="Button16" runat="server" Text="Search Item" Width="47px" />
                            <asp:Button ID="Button19" runat="server" Text="Button" />
                        </td>
                        <td class="style221">
                            <asp:Label ID="Label1" runat="server" Text="Replace with" Visible="False"></asp:Label>
                            &nbsp;</td>
                        <td class="style228">
                            <cc2:C1ComboBox ID="C1ItemReplace" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" DropDownPositioningMode="RightTop"
                                EmptyText="" FooterText="" Height="21px" Text="Enter/Select"
                                ToolTip="Enter or Select Existing Item" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista" Width="162px" Visible="False">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style221">
                            130- Date</td>
                        <td class="style185">
                            <cc2:C1ComboBox ID="C1Date" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" style="text-align: justify"
                                Text="" Height="22px" IsEditable="False"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style185">
                            <asp:Button ID="Button13" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="style226">
                            110-Item Type</td>
                        <td class="style180">
                            <cc2:C1ComboBox ID="C1ItemType" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                DropDownPositioningMode="RightTop" DropDownResizable="True"
                                TemplateItemHighlighted="False" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista" ForceSelectionText="True" IsEditable="False">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style209">
                            <asp:Button ID="Button11" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                        <td class="style181" colspan="5">
                            &nbsp;&nbsp;&nbsp; 120 - ItemA Type</td>
                        <td class="style185">
                            <cc2:C1ComboBox ID="C1ItemAType" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" DropDownPositioningMode="TopLeft"
                                style="text-align: left" Text="Select" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista" IsEditable="False">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style185">
                            <asp:Button ID="Button14" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                    </tr>
                    <tr>
                        <td class="style211">
                            101-Manufacturer</td>
                        <td class="style212">
                            <cc2:C1ComboBox ID="C1Manufacturer" runat="server"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" Text="Enter/Select">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style213">
                            <asp:Button ID="Button12" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                        <td class="style214" colspan="5">
                            &nbsp; 111-Self Activation</td>
                        <td class="style219">
                            <cc2:C1ComboBox ID="C1SelfActivation" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select" IsEditable="False"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                         
                        <td class="style219">
                            <asp:Button ID="Button15" runat="server" Height="24px" style="text-align: left"
                                Text="?" Width="16px" />
                        </td>
                         
                    </tr>
                    <tr>
                    <td class="style200">
                            <span class="style199">140- Illustration</span></td>
                            <td class="style206">
                                <cc2:C1ComboBox ID="C1Illustration" runat="server"
                                    DropDownPositioningMode="RightTop" ShowTrigger="False" Text=""
                                    UseEmbeddedVisualStyles="True" VisualStyle="Vista">
                                </cc2:C1ComboBox>
                           </td>
                            <td colspan="2">
                                <asp:Button ID="Button1" runat="server" Height="24px" Text="Load Image...."
                                    Width="156px" />
                        </td>
                            <td colspan="4">
                                <asp:Button ID="Button18" runat="server" Text="Show" />
                        </td>
                            </tr>
                            <tr><td colspan="10">=<asp:Image ID="Image1" runat="server" Height="370px"
                                    Width="424px" />
                           </td>
                           </tr>
                    </table>
            </asp:View>
            <asp:View ID="View2" runat="server">
             <table class="style1">
                          <tr>
                        <td class="style170" colspan="2">
                            <strong><span class="style178">Identification</span></strong></td>
                        <td class="style173">
                            &nbsp;</td>
                        <td class="style185">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style204">
                            200-Country Org</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1CountryOrigin" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" MaxLength="3" Text="Select"
                                Height="20px" IsEditable="False" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista" DropDownPositioningMode="RightTop" Width="51px">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            210-User Country</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1CountryUser" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                IsEditable="False" UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" Width="51px">
                            </cc2:C1ComboBox>
                        </td>
                        <td class="style49" colspan="2" rowspan="17">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style204">
                            230-User(s)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1Users" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                IsEditable="False" UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" Width="51px">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            220-Life Cycle St</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1LifeCycleStatus" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                IsEditable="False" UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" style="height: 22px">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style194">
                            240-NSN (xxxx-xx-xxx-xxxx)</td>
                        <td class="style195">
                            <cc2:C1ComboBox ID="C1NSN" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            250-ItemA Type</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemAType" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                IsEditable="False" UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style190" colspan="2">
                            <strong>ItemB Levels</strong></td>
                    </tr>
                    <tr>
                        <td class="style191" rowspan="0">
                            260-Rotation Min. (xxx,xxx)</td>
                        <td class="style192" rowspan="0">
                            <cc2:C1ComboBox ID="C1RotationMinimum" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" style="text-align: justify">
                            </cc2:C1ComboBox>
                            </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            261-Rotation Max. (xxx,xxx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1RotationMaximum" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            262-Acceleration Min. (xxx,xxx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation9" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                DropDownPositioningMode="TopRight" UseEmbeddedVisualStyles="True"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            263-Acceleration Dur. Min (xx.xx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation10" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            264-Acceleration Max (xxx,xxx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation11" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            265-Acceleration Dur. Max(xx.xx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation12" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style187">
                            266-Min Programmable Time (xx)</td>
                        <td class="style188">
                            <cc2:C1ComboBox ID="C1ItemDesignation13" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            267-Max Programmable Time (xx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation14" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            268-Max Flight Time (xx,xxx)</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation15" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Enter/Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            269-Features</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation16" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td class="style204">
                            270-Course Correcting Features</td>
                        <td class="style196">
                            <cc2:C1ComboBox ID="C1ItemDesignation17" runat="server" AutoComplete="False"
                                AutoFilter="False" CausesValidation="False" Text="Select"
                                VisualStyle="Vista">
                            </cc2:C1ComboBox>
                        </td>
                    </tr>
                </table>

            </asp:View>

</asp:MultiView>
        <asp:Button ID="btnBack" runat="server" Text="Back" />
        <asp:Button ID="btnNext" runat="server" Text="Next" />
        <asp:Button ID="btnSave" runat="server" Text="Save" />
        <asp:Button ID="btnPrev" runat="server" Text="&lt;&lt; Prev" />
        <asp:Button ID="btnNextA" runat="server" Text="Next &gt;&gt;" />
        <asp:Button ID="Button7" runat="server" Text="|&lt;  First" Width="67px" />
        <asp:Button ID="Button8" runat="server" Text="Last &gt;|" />
        <asp:TextBox ID="RecordNumber" runat="server"></asp:TextBox>
    </p>
    <script type="text/javascript">     //using C1ClientSide Event function
 onBeforeCellUpdate(grid, args) {
 var numberpattern = /\d{3}\-\d{2}\-\d{3}\-\d{5}$/;
 if (args.get_cell().get_column().get_dataField() == "Phone")
 {
 var Myinput = args.get_cell().get_value();
 var matchvalue = (Myinput.match(numberpattern)) ? true : false;
 if (!matchvalue) { args.set_cancel(true);
 window.alert("Please enter (999-99-999-99999) format only.");
 args.get_cell().get_contentControl().getElementsByTagName("input")[0].focus(); } } }
 </script>
    </asp:Content>


Code: Save button (i.e Save Manufacturer data)

Protected Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
        Dim xyz() As String = New String() {"Manufacturer"}
        Dim i As Integer
        i = 0
        For i = 0 To 1
            Dim curXYZ = xyz(i)
            Dim MyFix As XDocument = XDocument.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim xid As String
            xid = curXYZ & "_ID"
            Dim LargestFixID = (From el In MyFix.Descendants(curXYZ & "Table") Select CInt(el.<xid>.Value)).ToList
            LargestFixID.Sort()
            Dim xtable As String
            xtable = curXYZ & "Table"
            Dim xcontrol1 As String
            ' xcontrol1 = CType(Me.Controls("C1" & curXYZ), C1ComboBox).Text
            MsgBox(xtable)
            xcontrol1 = CType(Me.FindControl("C1" & curXYZ), C1ComboBox).Text.ToString
            MsgBox(xcontrol1)
            Dim xcontrol As String
            xcontrol = "Me.C1" & curXYZ & ".Text.ToString"
            MsgBox(xcontrol1)
            Dim CheckForItemFix = (From el In MyFix.Descendants(xtable).Elements(curXYZ) Select el.Value).ToList
            If Not CheckForItemFix.Contains(xcontrol1) Then
                Dim xNew As XElement = New XElement(xtable)
                xNew.Add(New XElement(xid, (LargestFixID.Last() + 1)))
                xNew.Add(New XElement(curXYZ, xcontrol1))
                MyFix.Root.Add(xNew)
                MyFix.Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            End If

            Dim searchFix As String = xcontrol1
            Dim searchIdFix As String = Nothing
            Dim domFix As New XmlDocument()
            domFix.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim listFix As XmlNodeList = domFix.SelectNodes("//" & xtable)
            If CheckForItemFix.Contains(xcontrol1) Then
                For Each node As XmlNode In listFix
                    If node(curXYZ).InnerText.Equals(searchFix) Then
                        searchIdFix = node(xid).InnerText
                        Exit For
                    End If
                Next
            End If
        Next

    End Sub

'Declarations:

Imports System.Xml
Imports System
Imports System.Text
Imports C1.Web.UI.Controls.C1ComboBox
Imports C1.Web.UI.Controls
Well, from that page you posted, the control C1Receiver doesn't exist.

So calling Me.FindControl with an ID nonexistent is returning Nothing. So after then, calling a method or property, like Text, on Nothing generates the error :  Object reference not set to an instance of an object.

So, either you ensure that all the controls with the ID you need really exist or you add this piece of code.


If Me.FindControl("C1" & curXYZ) IsNot Nothing Then xcontrol1 = CType(Me.Controls("C1" & curXYZ), C1ComboBox).Text

Open in new window

Hi,

I am testing the project with the C1manufacturer control

Dim xyz() As String = New String() {"Manufacturer"}

Only Manufacturer is included in the xyz() string.


it exist in the .aspx file:

 <td class="style212">
                            <cc2:C1ComboBox ID="C1Manufacturer" runat="server"
                                UseEmbeddedVisualStyles="True" VisualStyle="Vista"
                                DropDownPositioningMode="RightTop" Text="Enter/Select">
                            </cc2:C1ComboBox>
                        </td>


Victor
Ok, I presume then that the problem is coming from the fact that your control is not inside the page, but within a container.

Let's try then this recursive method :
 
Public Function searchControl(idToSearch As String, obj As Control) As Control
 Dim foundControl As Control = obj.FindControl(idToSearch)
 If foundControl IsNot Nothing Then Return foundControl

 For i As Integer = 0 To obj.Controls.Count - 1
  If obj.Controls(i).Count = 0 Then Continue For

  foundControl = searchControl(idToSearch, obj.Controls(i))
  If foundControl IsNot Nothing Then Return foundControl
 Next

 Return Nothing
End Function

Open in new window


Hi,

Thanks for the code, when I add it to my button click event, what value to I pass to idToSearch?

Victor
Call the function like this :
searchControl("C1" & curXYZ, Me)

Hi,

I'm getting the folowing error message in the Function: "Count is not a member of System.Web.UI.Control"

The other problem I noticed when Using multiple files in the xyz() string, I am only able to save data for the last file in the list, is thetre a way MyFix variable to save the data for each file in the xyz() string?

Code:
  Dim xyz() As String = New String() {"Manufacturer"}
        Dim i As Integer
        i = 0
        For i = 0 To 1
            Dim curXYZ = xyz(i)
            Dim MyFix As XDocument = XDocument.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim xid As String
            xid = curXYZ & "_ID"
            Dim LargestFixID = (From el In MyFix.Descendants(curXYZ & "Table") Select CInt(el.<xid>.Value)).ToList
            LargestFixID.Sort()
            Dim xtable As String
            xtable = curXYZ & "Table"

            Dim xcontrol1 As String = ""
            searchControl("C1" & curXYZ, Me)
            'If Me.FindControl("C1" & curXYZ) IsNot Nothing Then xcontrol1 = CType(Me.Controls("C1" & curXYZ), C1ComboBox).Text
            MsgBox(xcontrol1)
            Dim CheckForItemFix = (From el In MyFix.Descendants(xtable).Elements(curXYZ) Select el.Value).ToList
            If Not CheckForItemFix.Contains(xcontrol1) Then
                Dim xNew As XElement = New XElement(xtable)
                xNew.Add(New XElement(xid, (LargestFixID.Last() + 1)))
                xNew.Add(New XElement(curXYZ, xcontrol1))
                MyFix.Root.Add(xNew)
                MyFix.Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            End If

            Dim searchFix As String = xcontrol1
            Dim searchIdFix As String = Nothing
            Dim domFix As New XmlDocument()
            domFix.Load(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))
            Dim listFix As XmlNodeList = domFix.SelectNodes("//" & xtable)
            If CheckForItemFix.Contains(xcontrol1) Then
                For Each node As XmlNode In listFix
                    If node(curXYZ).InnerText.Equals(searchFix) Then
                        searchIdFix = node(xid).InnerText
                        Exit For
                    End If
                Next
            End If
        Next

Public Function searchControl(ByVal idToSearch As String, ByVal obj As Control) As Control
        Dim foundControl As Control = obj.FindControl(idToSearch)
        If foundControl IsNot Nothing Then Return foundControl

        For i As Integer = 0 To obj.Controls.Count - 1
            If obj.Controls(i).Count = 0 Then Continue For
            foundControl = searchControl(idToSearch, obj.Controls(i))
            If foundControl IsNot Nothing Then Return foundControl
        Next
        Return Nothing
    End Function
Hello,

Is there a way to do

 MyFix(i).Root.Add(xNew)
 MyFix(i).Save(Server.MapPath("~/App_Data/" & curXYZ & ".xml"))

To avoid using an If ststement for each value of curXYZ?

Vctror
ASKER CERTIFIED SOLUTION
Avatar of djon2003
djon2003
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for all your help.