Asp button with different button type

后端 未结 5 431
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 06:11

Is it possible to have an asp button that isn\'t rendered with a type=\"submit\" tag. I don\'t want the button to submit the form, so I\'d like to have it as

相关标签:
5条回答
  • 2020-12-06 06:30

    Using the attribute UseSubmitBehaviour="false" solved my problem

    <asp:Button ID="button1" runat="server" UseSubmitBehavior="false" Text="just a button" />
    

    This attribute is available since .Net v2.0, for more information: Button.UseSubmitBehavior Property

    0 讨论(0)
  • 2020-12-06 06:43

    Two ways:

    1) Add a OnClientClick property which returns false.

     <asp:Button runat="Server" ONClientClick="return true"/>
    

    2) Or use a HTML Control i.e:

     <input type="button" id="testButton" value="Regular Button" runat="server"/>
    
    0 讨论(0)
  • 2020-12-06 06:55

    If you don't want the button to submit, do you need a button at all ? After all, it doesn't do anything before it posts back to the server. You can might as well just use an <input type="button".

    That being said, you can use javascript to prevent a postback:

    <asp:Button runat="server" OnClientClick="return false;" />
    
    0 讨论(0)
  • 2020-12-06 06:55

    You can just set UseSubmitBehavior="false" and it will render type="button" instead of type="submit" (.net 4 at least)

    0 讨论(0)
  • 2020-12-06 06:56

    You need to prevent postback when pressing on an <asp:Button>

    Check this

    0 讨论(0)
提交回复
热议问题