简体   繁体   中英

asp net - button with commandname not submit

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM