1

How to use bootstrap button in aspx and click event in server side. i have button like :

example.aspx:

    <button class="btn btn-orange btn-lg" runat="server" onclick="btnclick_click"><b><i class="fa fa-sign-out"></i> LOGOUT</b></button>

this is the button that i taken aspx file with bootstrap button with onclick event :

example.aspx.cs :

here i am accessing button onclick event but its not triggering

protected void btnclick_click(object sender, EventArgs e)
    {
        Response.Redirect("page2.aspx");
    }

2 Answers 2

3

First way

You can use an asp.net button to trigger that as

<asp:Button id="btnLogout"  runat="server" Text="  LOGOUT  " OnClick="btnclick_click" CssClass="fa fa-sign-out"></asp:Button>

To have the bootstrap theme you just set your CssClass

Second way

You keep your code as it but because you make it run on server and its an html button control you MUST use the onserverclick to make it call your code behind function, and your code will be:

<button class="btn btn-orange btn-lg" runat="server" 
    onserverclick="btnclick_click"><b><i class="fa fa-sign-out"></i> LOGOUT</b></button>
Sign up to request clarification or add additional context in comments.

11 Comments

But what about bootstrap class of button i used , and not getting correct alignment . i have used row and i am placing button inside <div class="col-md-2" style="text-align: left">
@chetu I have update my answer - just use the onserverclick and you done
and also not getting that fa- sign-out icon in button .. there is no way to handle bootstrap button directly in server side in asp.net
@chetu yes there is, change the onclick to onserverclick and you done... see my updated answer
onserverclick can i use this directly on bootstrap button ?
|
0
<asp:LinkButton ID="ModalDummy" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalDummy_ModalPopupExtender" runat="server" BehaviorID="ModalDummy_ModalPopupExtender" TargetControlID="ModalDummy" PopupControlID="PanelPopup">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelPopup" runat="server" DefaultButton="ButtonContactSend">
    your popup
</asp:Panel>


ModalDummy_ModalPopupExtender.Show();

1 Comment

While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.