We help IT Professionals succeed at work.

ASP.net button click event in Site.Master

Murray Brown
Murray Brown asked
on
Hi
In my ASP.net Site Master whose markup code is shown below I have the following button
     <button class="btn btn-primary" ID="btnGetStarted">Get started</button>
I want to run VB.net code behind this but when I double click on it it does not create a VB.net click event



<%@ Master Language="VB" AutoEventWireup="true" CodeBehind="Site.master.vb" Inherits="Office2Web.SiteMaster" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><%: Page.Title %> Office2Web Microsoft Office and Web Solutions</title>

    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>

    <webopt:bundlereference runat="server" path="~/Content/css" />
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap" rel="stylesheet">
</head>
<body>
    <form runat="server">
        <asp:ScriptManager runat="server">
            <Scripts>
                <%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%>
                <%--Framework Scripts--%>
                <asp:ScriptReference Name="MsAjaxBundle" />
                <asp:ScriptReference Name="jquery" />
                <asp:ScriptReference Name="bootstrap" />
                <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
                <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
                <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
                <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
                <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
                <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
                <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
                <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
                <asp:ScriptReference Name="WebFormsBundle" />
                <%--Site Scripts--%>
            </Scripts>
        </asp:ScriptManager>

        <!-- Navbar -->
        <nav class="navbar navbar-default">
            <div class="container">
                <div class="navbar-header">
                    <a class="navbar-brand" runat="server" href="~/">
                        <img src="Resources/images/logo/office2web-logo.svg" alt="The Office2Web logo"/>
                    </a>
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-collapse" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <div class="collapse navbar-collapse" id="main-menu-collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a runat="server" href="~/">Home</a></li>
                        <li><a runat="server" href="~/About">About</a></li>
                        <li class="dropdown">
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Services
                            <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a runat="server" href="~/Microsoft_Office_Solutions">Microsoft Office Solutions</a></li>
                                <li><a runat="server" href="~/Web_Applications">Web Applications</a></li>
                                <li><a runat="server" href="~/Combined_Web_And_Office">Combined Web & Office</a></li>
                                <li><a runat="server" href="~/Access_Services">Access Services</a></li>
                            </ul>
                        </li>
                        <li><a runat="server" href="~/Contact">Contact</a></li>
                    </ul>
                </div>
            </div>
        </nav>

        <script type="text/javascript">
            (function ($) {
                $(document).ready(function () {
                    $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function (event) {
                        event.preventDefault();
                        event.stopPropagation();
                        $(this).parent().siblings().removeClass('open');
                        $(this).parent().toggleClass('open');
                    });
                });
            })(jQuery);
        </script>

        <!-- Content -->
        <div class="container-fluid p-0">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
        </div>

        <!-- Footer -->
        <footer class="footer">
            <div class="container">
                <div class="footer-form">
                    <div class="row">
                        <div class="col-sm-12 col-md-6">
                            <h2>Get a free consultation</h2>
                                          <p>Initial consultation is free. Thereafter charges apply.</p>
                        </div>
                        <div class="col-sm-12 col-md-4">
                            <div class="form-group">
                                <input type="email" placeholder="Enter your email address" class="form-control" />
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-2">
                            <button class="btn btn-primary" ID="btnGetStarted">Get started</button>
                        </div>
                    </div>
                </div>
                <hr />
                <div class="footer-bottom">
                    <div class="row">
                        <div class="col-sm-12 col-md-6">
                            <p>&copy; <%: DateTime.Now.Year %> - Office2Web Pty Ltd</p>
                        </div>
                    </div>
                </div>
            </div>
        </footer>
    </form>
</body>
</html>
Comment
Watch Question

Director, Information Systems
BRONZE EXPERT
Commented:
Make the control an ASP.Net control and wire up an OnClick event for your button.

Instead of:
   <button class="btn btn-primary" ID="btnGetStarted">Get started</button>
Use:
   <asp:Button ID="btnGetStarted" runat="server" Text="Get Started" OnClick="btnGetStarted_Click" />

More information here:
https://asp-net-example.blogspot.com/2008/10/button-example-how-to-use-onclick-event.html 


Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much