locked
I have a problem....I have a dropdownlist populated with names from xml file...I have item with "add new name"..when user clicks it, there should be a popup to add name and then update xml file also add it to dropdownlist..please help anyone RRS feed

  • Question

  • User767034699 posted
    <head runat="server">
       <script  type ="text/jscript"  src="Scripts/jquery-1.11.0.min.js"></script>
        <script type ="text/jscript" src ="Scripts/jquery-1.11.0.js"></script>
         <script type ="text/jscript"  src="Scripts/jquery-1.8.2.js"></script>
        <script type ="text/jscript"  src="Scripts/jquery-ui-1.8.24.js"></script>
        <link href="Content/jquery-ui.css" rel="stylesheet" />
        <script type ="text/jscript">
            $(function () {
                $("#popDiv").dialog({
                    autoOpen: false,
                    autoResize: true,
                    resizable: false,
                    title: "Add Name",
                    open: function (event, ui) {
                        $(this).parent().appendTo("form");        //allow .Net buttons to post back
                    }
                });
    
            });
            function change() {
                var selectedValue = $("#<%=DDL1.ClientID%>").val();
                if (selectedValue == "Add your name") {
                      $("#popDiv").dialog("open");
                }
            }
        </script>
         
                <title>IN House OFFICE CONFIRMATION</title>
        <link href="Site.css" rel="stylesheet" type="text/css" />
       
           <style type="text/css">
            .style1
            {
                width: 100%;
                height: 93px;
            }
        </style>
     
    </head>
     <?php flush(); ?>
     <body>
     
    <!-- Preloader -->
    <div id="Div1"></div>
        <div id="Div2">
         
      </div>
    <script type ="text/jscript" >
        $(window).load(function () { $("#spinner").fadeOut(5000); })
    </script>
    
    
    
      
        <form id="form1" runat="server">
       
         <div class="page">
             <br />
             <table class="style1">
                 <tr>
                     <td bgcolor="Maroon">
                         <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/thCAWVZOKA.jpg" 
                             style="z-index: 1; left: 675px; top: -2px; ; height: 94px; width: 304px" />
                     </td>
                 </tr>
             </table>
         
           
             <br />
        
             <asp:Label ID="Label1" runat="server" Text="Choose Contact Names:"></asp:Label>
      
             <br />
             <div>
             <asp:DropDownList ID="DDL1" runat="server" AutoPostBack ="true" OnSelectedIndexChanged ="Selection_Change"  onchange="change();" >
            <asp:ListItem Value ="-1">
            ----SELECT NAME----
                </asp:ListItem>
             <asp:ListItem Text="Add your name..." Value="Add your name"></asp:ListItem>
             </asp:DropDownList>    
                <div id="popDiv" style="display:none">
                your name:<asp:TextBox runat="server" ID="txtName"></asp:TextBox><br />
                <asp:Button ID="Button1" runat="server" Text="submit" />
            </div>
            </div>
             <br />
             <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="Up" runat="server" UpdateMode ="Conditional">
           <ContentTemplate>
     <strong ><asp:Label ID="lbltot" runat="server"></asp:Label></strong>
     <div class="wrapper">
        <div class="updateProgress">
         <asp:UpdateProgress ID="UpdateProgress1"  runat="server" 
                 DynamicLayout="true" DisplayAfter="0" >
           <ProgressTemplate>        
                 &nbsp;<img alt="Updating in Progress..." src="Images/icon_inprogress.gif" 
                     style="width: 100px; height: 96px" />
                   Please wait while loading....
             </ProgressTemplate>
    </asp:UpdateProgress>
        </div>
            <asp:GridView ID="GridView1" DataKeyNames="DISPREC_ID" runat="server" ShowHeaderWhenEmpty="True" 
                AutoGenerateColumns="False"
                BackColor="White"
                BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
                Style="z-index: 1; left: 37px; top: 36px; height: 179px; width: 938px">
             
             <EmptyDataTemplate >
           <div id="msg"> <strong>PLEASE SELECT CONTACT TO VIEW BAGS IN OFFICE</strong> </div>
        </EmptyDataTemplate>
                         
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:BoundField DataField="DISPREC_ID" HeaderText="DISPREC_ID" ReadOnly="true"
                        Visible="False" />
                    <asp:BoundField DataField="DestinationOffice" HeaderText="Destination_Office" ReadOnly="true" Visible="False" />
                    <asp:BoundField DataField="TrackingNumber" HeaderText="Tracking_Number" ReadOnly="true" />
                    <asp:BoundField DataField="DispatchDate" HeaderText="Dispatch_Date" ReadOnly="true" />
                    <asp:TemplateField HeaderText="Confirmation_" SortExpression="Confirmation_">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Confirmation_") %>'
                                AutoPostBack="true" OnCheckedChanged="checked_"
                                Text='<%# If(Eval("Confirmation_").ToString().Equals("True"), "  Received ", "  Not Received ") %>' />
                         </ItemTemplate>
                        </asp:TemplateField>
    
                      
                         </Columns>
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <SortedAscendingCellStyle BackColor="#FDF5AC" />
                <SortedAscendingHeaderStyle BackColor="#4D0000" />
                <SortedDescendingCellStyle BackColor="#FCF6C0" />
                <SortedDescendingHeaderStyle BackColor="#820000" />
            
    
            </asp:GridView>
           </div>
           
            <asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="300"></asp:Timer>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID ="DDL1" EventName ="SelectedIndexChanged" />
        </Triggers>
    </asp:UpdatePanel>

    This is my linq code which will be updating the xml after user added new name

    Protected Sub add()
            Dim xdoc1 As New XmlDocument()
            xdoc1.Load("~/dsp6.xml")
            Dim dsp As XmlNode = xdoc1.CreateElement("DSP")
    
            Dim contact As XmlNode = xdoc1.CreateElement("Contact4")
            contact.InnerText = DDL1.ToString()
            dsp.AppendChild(contact)
    
            xdoc1.DocumentElement.AppendChild(dsp)
            xdoc1.Save("~/dsp6.xml")
        End Sub

    this is my xml file

    <?xml version="1.0" encoding="utf-8"?>
    <MAIN>
    <DISP DISPREC_ID = "CCG/2014/00009351">
      <DestinationOffice>ISAN</DestinationOffice>
      <TrackingNumber>RG6045Z</TrackingNumber>
      <DispatchDate>06-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1>A BOCK</Contact1>
      <Contact2>R NDLOVU </Contact2>
      <Contact3>S MIYA &amp; LD.RAKUMAKO</Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    <DISP DISPREC_ID = "CCG/2014/00016385">
      <DestinationOffice> WEST </DestinationOffice>
      <TrackingNumber>RG6001Z</TrackingNumber>
      <DispatchDate>08-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1> </Contact1>
      <Contact2> </Contact2>
      <Contact3> </Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    <DISP DISPREC_ID = "CCG/2014/00032015">
      <DestinationOffice>WIT</DestinationOffice>
      <TrackingNumber>RG60603Z</TrackingNumber>
      <DispatchDate>10-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1>MD JamesI</Contact1>
      <Contact2> </Contact2>
      <Contact3>TT PUKUILE</Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    <DISP DISPREC_ID = "CCG/2014/00040323">
      <DestinationOffice>BRAAMFON</DestinationOffice>
      <TrackingNumber>RG60431Z</TrackingNumber>
      <DispatchDate>13-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1>KR Peters</Contact1>
      <Contact2>HC Jeffery</Contact2>
      <Contact3>M MAKE</Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    <DISP DISPREC_ID = "CCG/2014/00052226">
      <DestinationOffice>WIT</DestinationOffice>
      <TrackingNumber>RG60464Z</TrackingNumber>
      <DispatchDate>14-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1>MD BENI</Contact1>
      <Contact2> </Contact2>
      <Contact3>TT KILE</Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    <DISP DISPREC_ID = "CCG/2014/00057926">
      <DestinationOffice>STRUBEN</DestinationOffice>
      <TrackingNumber>RG6044Z</TrackingNumber>
      <DispatchDate>14-01-2014</DispatchDate>
      <Confirmation>FALSE</Confirmation>
      <UserConfirmation_>N</UserConfirmation_>
      <Contact1>MR ALLIES</Contact1>
      <Contact2>N MARTIN</Contact2>
      <Contact3>D BEZUIDENHOUT</Contact3>
      <DATECONFIRMED_>N</DATECONFIRMED_>
    </DISP>
    </MAIN>
    




    Monday, April 7, 2014 3:02 AM

Answers

  • User697462465 posted

    Hi tonyR6,

    Please try to change your js code as below:

    function change() {
                var selectedValue = $("#<%=DDL1.ClientID%>").val();
                if (selectedValue == "Add your name") {
                      $("#popDiv").dialog("open");
                      return false;
                }
            }

    Change the dropdownlist as below:

    <asp:DropDownList ID="DDL1" runat="server" AutoPostBack ="true" OnSelectedIndexChanged ="Selection_Change"  onchange="return change();" >
            <asp:ListItem Value ="-1">
            ----SELECT NAME----
                </asp:ListItem>
             <asp:ListItem Text="Add your name..." Value="Add your name"></asp:ListItem>
             </asp:DropDownList>    

    Hope it helps.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 5:00 AM

All replies

  • User2117486576 posted

    You have autopostback=true for the ddl.  Therfore if you want to handle the onchange event on the client you will need to prevent the postback.  You can do this by returning false in the onchange event handler after opening the popup.

    Monday, April 7, 2014 6:14 PM
  • User767034699 posted

    yeah i see...Im stil new to jquery and learning so Im not quite sure how to return false?....if i could be able to add new name to the dropdownlist and be able to update the xml file...I have linq query on dropdownlist selection criteria that select data from the xml file...

    Tuesday, April 8, 2014 3:05 AM
  • User697462465 posted

    Hi tonyR6,

    Please try to change your js code as below:

    function change() {
                var selectedValue = $("#<%=DDL1.ClientID%>").val();
                if (selectedValue == "Add your name") {
                      $("#popDiv").dialog("open");
                      return false;
                }
            }

    Change the dropdownlist as below:

    <asp:DropDownList ID="DDL1" runat="server" AutoPostBack ="true" OnSelectedIndexChanged ="Selection_Change"  onchange="return change();" >
            <asp:ListItem Value ="-1">
            ----SELECT NAME----
                </asp:ListItem>
             <asp:ListItem Text="Add your name..." Value="Add your name"></asp:ListItem>
             </asp:DropDownList>    

    Hope it helps.

    Best Regards,
    Terry Guo

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 5:00 AM
  • User767034699 posted
      Protected Sub Selection_Change(ByVal sender As Object, ByVal e As EventArgs) Handles DDL1.SelectedIndexChanged
            ''here its where I query xml file after selection
    
            Timer1.Enabled = False
            If DDL1.SelectedValue = "-1" Then
                Session("OFF") = "NONE"
                Me.lbltot.Visible = False
            Else
                Me.lbltot.Visible = True
                Session("OFF") = Request.QueryString("office")
            End If
            IEnumerable()
        End Sub

    if only i could be able to add a new name using that popup dialog box on the dropdownlist then re-bind the dropdownlist as well save changes to xml file...thats the part Im finding it difficult
    ok thanx terry but here is the tricky part...I populate names using this

      Protected Sub Populate_Office()
            ''populating the dropdownlist
            Dim query1 = (From d In XElement.Load(Server.MapPath("~/dsp6.xml")).Elements()
                                         Where (CStr(d.Element("DestinationOffice").Value = Request.QueryString("office")))
                                             Select contact1 = d.Element("Contact1").Value,
                                             contact2 = d.Element("Contact2").Value,
                                             contact3 = d.Element("Contact3").Value
                                             Order By contact1, contact2, contact3 Ascending)
    
            For Each d In query1
                If Not d.contact1 = Nothing Then DDL1.Items.Add(d.contact1)
                If Not d.contact2 = Nothing Then DDL1.Items.Add(d.contact2)
                If Not d.contact3 = Nothing Then DDL1.Items.Add(d.contact3)
    
                ''removing duplicates
                For i As Int16 = 0 To DDL1.Items.Count - 2
                    For j As Int16 = DDL1.Items.Count - 1 To i + 1 Step -1
                        If DDL1.Items(i).ToString = DDL1.Items(j).ToString Then
                            DDL1.Items.RemoveAt(j)
                        End If
                    Next
                Next
            Next
    
        End Sub

    but now i cant query the xml file after setting the return false on the dropdownlist
    Tuesday, April 8, 2014 10:21 AM
  • User767034699 posted

    how can I make a click event on the pop up dialog so that a user can add a name to the dropdownlist if possible update xml with the new contact name....its been two weeks trying to figure it out....if someone could help

    Tuesday, April 15, 2014 2:59 AM