Hi,

I have a question regarding an issue on submitting a form multiple times. For some reason, my form takes one submit, but then the others, I don't see changes of result. Here is the app:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.XML" %>

<script runat="server">   

Sub submit(ByVal sender As Object, ByVal e As EventArgs)
              
    mess.Text = "You selected " & drop1.SelectedItem.Text
    Dim file As String = Context.Server.MapPath("music.xml")
    Dim document As XmlDocument = New XmlDocument()
    document.Load(file)

    Dim songList As XmlNodeList
    songList = document.SelectNodes("/music_songs/song[category='" & drop1.SelectedItem.Text & "']")    

    Dim song As XmlNode
    For Each song In songList
    
    Dim title As XmlNode = song.FirstChild
    songNodesOut.Text &=  "<b>Title:</b> " & title.InnerText & "<br/>"

    Dim category As XmlNode = title.NextSibling
    SongNodesOut.Text &= "<b>Category:</b> " & category.InnerText & "<br /><hr />"
    
  Next
        
end Sub
</script>

<html>
<body>
<form runat="server">

<div>
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Rock</asp:ListItem>
<asp:ListItem>Blues</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>
</form>

<p><asp:label id="mess" runat="server"/></p>
<asp:Label id="songNodesOut" runat="server" />
</div>
</body>
</html>

In other words, if I first make Rock as my selection from drop down list, the songs are listed correctly, but if I try and select on the Blues, even though those songs exist, I only see the same songs from the other list. Is there something here that I missed?

Thanks for your help.

Hi,

I have a question regarding an issue on submitting a form multiple times. For some reason, my form takes one submit, but then the others, I don't see changes of result. Here is the app:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.XML" %>

<script runat="server">   

Sub submit(ByVal sender As Object, ByVal e As EventArgs)
              
    mess.Text = "You selected " & drop1.SelectedItem.Text
    Dim file As String = Context.Server.MapPath("music.xml")
    Dim document As XmlDocument = New XmlDocument()
    document.Load(file)

    Dim songList As XmlNodeList
    songList = document.SelectNodes("/music_songs/song[category='" & drop1.SelectedItem.Text & "']")    

    Dim song As XmlNode
    For Each song In songList
    
    Dim title As XmlNode = song.FirstChild
    songNodesOut.Text &=  "<b>Title:</b> " & title.InnerText & "<br/>"

    Dim category As XmlNode = title.NextSibling
    SongNodesOut.Text &= "<b>Category:</b> " & category.InnerText & "<br /><hr />"
    
  Next
        
end Sub
</script>

<html>
<body>
<form runat="server">

<div>
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Rock</asp:ListItem>
<asp:ListItem>Blues</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>
</form>

<p><asp:label id="mess" runat="server"/></p>
<asp:Label id="songNodesOut" runat="server" />
</div>
</body>
</html>

In other words, if I first make Rock as my selection from drop down list, the songs are listed correctly, but if I try and select on the Blues, even though those songs exist, I only see the same songs from the other list. Is there something here that I missed?

Thanks for your help.

Just a note,

I don't think my problem here has been solved yet. I have fixed it up and implemented the is Not Page.IsPostBack function into mine, but it does not seem to make a difference.

When I get the first batch of results back, if I want to make another selection, then I am only returned with the first set the second time. Yet, I don't think this is multiple clicking the submit button several times. Here is the code of what I edited,

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.XML" %>

<script runat="server">   
    
    Sub Page_Load()
        If Not Page.IsPostBack Then
            mess.Text = "<p style='color:red;font-weight:bold'>Please make a selection of the type of song list you would like to see from my collection</p>"
        Else
            mess.Text = "<p>You selected " & drop1.SelectedItem.Text & "</p>"
        End If
    End Sub
    Sub submit(ByVal sender As Object, ByVal e As EventArgs)
   
        Dim file As String = Context.Server.MapPath("music.xml")
        Dim document As XmlDocument = New XmlDocument()
        document.Load(file)

        Dim songList As XmlNodeList
        songList = document.SelectNodes("/music_songs/song[category='" & drop1.SelectedItem.Text & "']")

        Dim song As XmlNode
        For Each song In songList
    
            Dim title As XmlNode = song.FirstChild
            songNodesOut.Text &= "<b>Title:</b> " & title.InnerText & "<br/>"

            Dim category As XmlNode = title.NextSibling
            songNodesOut.Text &= "<b>Category:</b> " & category.InnerText & "<br />"
    
            Dim album As XmlNode = category.NextSibling
            Dim artist As XmlNode = album.NextSibling
            songNodesOut.Text &= "<b>Artist:</b>" & artist.InnerText & "<br/>"
            songNodesOut.Text &= "<b>Album:</b> " & album.InnerText & "<br />"
   
            Dim date1 As XmlNode = artist.NextSibling
            Dim dateAttribute As XmlAttribute = date1.Attributes("added")
            songNodesOut.Text &= "<b>Date Added to Collection:</b> " & dateAttribute.Value & "<br/><hr/><br />"
   
        Next
		
    End Sub
</script>
<html>
<body>
<form runat="server">
<div>

<p><asp:label id="mess" runat="server"/></p>  
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Rock</asp:ListItem>
<asp:ListItem>Blues</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>

</form>
<asp:Label id="songNodesOut" runat="server" />
</div>
</body>
</html>

Anything is appreciated.

Protected Sub submit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        songNodesOut.Text = ""
        Dim file As String = Context.Server.MapPath("~/xml/Music.xml")
        Dim document As XmlDocument = New XmlDocument()
        document.Load(file)

        Dim songList As XmlNodeList
        ' songList = document.SelectNodes("/music_songs/song")
        songList = document.SelectNodes("//music_songs/song[@category='" & drop1.SelectedItem.Text & "']")

        Dim song As XmlNode
        For Each song In songList

            Dim title As XmlNode = song.FirstChild
            songNodesOut.Text &= "<b>Title:</b> " & title.InnerText & "<br/>"

            Dim category As XmlNode = title.NextSibling
            songNodesOut.Text &= "<b>Category:</b> " & category.InnerText & "<br />"

            'Dim album As XmlNode = category.NextSibling
            'Dim artist As XmlNode = album.NextSibling
            'songNodesOut.Text &= "<b>Artist:</b>" & artist.InnerText & "<br/>"
            'songNodesOut.Text &= "<b>Album:</b> " & album.InnerText & "<br />"

            'Dim date1 As XmlNode = artist.NextSibling
            'Dim dateAttribute As XmlAttribute = date1.Attributes("added")
            'songNodesOut.Text &= "<b>Date Added to Collection:</b> " & dateAttribute.Value & "<br/><hr/><br />"

        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            mess.Text = "<p style='color:red;font-weight:bold'>Please make a selection of the type of song list you would like to see from my collection</p>"
        Else
            mess.Text = "<p>You selected " & drop1.SelectedItem.Text & "</p>"
        End If
    End Sub
Protected Sub submit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        songNodesOut.Text = ""
        Dim file As String = Context.Server.MapPath("~/xml/Music.xml")
        Dim document As XmlDocument = New XmlDocument()
        document.Load(file)

        Dim songList As XmlNodeList
        ' songList = document.SelectNodes("/music_songs/song")
        songList = document.SelectNodes("//music_songs/song[@category='" & drop1.SelectedItem.Text & "']")

        Dim song As XmlNode
        For Each song In songList

            Dim title As XmlNode = song.FirstChild
            songNodesOut.Text &= "<b>Title:</b> " & title.InnerText & "<br/>"

            Dim category As XmlNode = title.NextSibling
            songNodesOut.Text &= "<b>Category:</b> " & category.InnerText & "<br />"

            'Dim album As XmlNode = category.NextSibling
            'Dim artist As XmlNode = album.NextSibling
            'songNodesOut.Text &= "<b>Artist:</b>" & artist.InnerText & "<br/>"
            'songNodesOut.Text &= "<b>Album:</b> " & album.InnerText & "<br />"

            'Dim date1 As XmlNode = artist.NextSibling
            'Dim dateAttribute As XmlAttribute = date1.Attributes("added")
            'songNodesOut.Text &= "<b>Date Added to Collection:</b> " & dateAttribute.Value & "<br/><hr/><br />"

        Next
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            mess.Text = "<p style='color:red;font-weight:bold'>Please make a selection of the type of song list you would like to see from my collection</p>"
        Else
            mess.Text = "<p>You selected " & drop1.SelectedItem.Text & "</p>"
        End If
    End Sub

I guess you were missing part
songList = document.SelectNodes("//music_songs/song[@category='" & drop1.SelectedItem.Text & "']")

No, as a matter of fact, it turned out all I had to do is to add

songNodesOut.Text = String.Empty

after submit has been declared and add a id to asp:button.

Thanks for your replies, a lot of these code snippets really helped me figure this out.

on start of Submit Button Event..
i wrote that already..
seems like u haven;t checked my code..!
songNodesOut.Text = ""

Yes, I must have missed that. This is actually better, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.