1

I'm wondering if it there is a solution to have a asp:Button with CommandName inside a ListView and make it run and execute the CommandName, but without refreshing the page (submit). I have a modal, so I don't like the page refreshing and then showing the modal.

<asp:Button runat="server" CommandName="Details" Text="Details" />

I've already tried UseSubmitBehaviour set to false without success.

EDIT:

Protected Sub lstvLadder_ItemCommand(sender As Object, e As ListViewCommandEventArgs)
        If e.CommandName = "Details" Then
            Dim lblRank As Label = TryCast(e.Item.FindControl("lblRank"), Label)
            Dim lblPoints As Label = TryCast(e.Item.FindControl("lblPoints"), Label)
            Dim lblTeam As Label = TryCast(e.Item.FindControl("lblTeam"), Label)
            Dim lblTeamLeader As Label = TryCast(e.Item.FindControl("lblTeamLeader"), Label)
            MUCH CODE HERE

        End If
End Sub

I want it to not refresh the page when button clicked, but I want it to run this function, commandname

If you want to see for yourself: here If you press the Details button on the right side, it refreshes the page then loads the modal instead of just loading the modal. The button I'm using to call it is the asp:Button above, and the ItemCommand block.

1 Answers1

0

I'm not completely sure what you are trying to accomplish. But if you are simply trying to prevent a postback you can simply try the following:

<asp:Button ID="btnId" runat="server" 
            CommandName="Details" 
            Text="Details"
            CommandArgument = "X"
            OnClick="btnId_Click" 
            OnClientClick="return false;" />

I left you with a few other properties on the asp:Button to look into to try an accomplish your problem. If you could go into further detail about what is happening and what you want to happen, I can try to help further. Like show you how to go about making an ajax call, but you may be able to accomplish what you are trying to do without one.

UPDATE:

I'm still unable to help further without access to more source information (your server code) but I'm providing a link to another answer regarding adding an UpdatePanel which will allow you to make a call to the server and not refresh the whole page when pressing the asp:button. Here is a link to the stackoverflow answer. Hope this helps.

Chef_Code
  • 241
  • 4
  • 11
  • When using return false, it doesn't run the Commandname, so doesn't work. I will update my question, please see – Luke Remming May 22 '17 at 06:19
  • Do you have a repository where I can view the source? – Chef_Code May 22 '17 at 17:04
  • Can you update your question to include all the parts of the problem in question... The client and server code at least... unless you have repository, then just point me to the repository. I need more context to help you. – Chef_Code May 22 '17 at 17:23
  • 1 last thing update your question's `tags` to include `webforms` and `vb.net` instead of javascript and jquery, you will get better help/attention to your question. – Chef_Code May 22 '17 at 17:35