suppose have aspx code here:
<%@ page language="c#" autoeventwireup="true" codebehind="searchcustomer.aspx.cs" inherits="webapplication1.eyeofheaven.searchcustomer" %> <!doctype html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="stylesheets/searchcustomerstyle.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <title>search customer</title> </head> <body> <form id="form1" runat="server"> <div class="row"> <div class="twelve columns"> <!-- header--> <div class="container"> <nav role="navigation" class="navbar navbar-inverse navbar-fixed-top"> <!-- brand , toggle grouped better mobile display --> <div class="navbar-header"> <button type="button" data-target="#navbarcollapse" data-toggle="collapse" class="navbar-toggle"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <!-- collection of nav links, forms, , other content toggling --> <div id="navbarcollapse" class="collapse navbar-collapse"> <ul class="nav navbar-nav"> <li><a href="eyeofheaven.aspx">home</a></li> <li class="dropdown"> <a data-toggle="dropdown" class="dropdown-toggle active" href="#">search<b class="caret"></b></a> <ul role="menu" class="dropdown-menu"> <li><a href="searchcustomer.aspx">search form(customer)</a></li> <li><a href="searchvehicle.aspx">search form(vehicle)</a></li> </ul> </li> </ul> </div> </nav> </div> </div> </div> <!-- search form customer--> <div id="searchcustomer" class="page-header"> <h3><span class="glyphicon glyphicon-th-large"></span>search customer</h3> </div> <div class="row"> <div class="col-md-4"><input type="text" size="20" class="form-control" placeholder="customer id"></div> <div class="col-md-4"> <select class="form-control" id="countries"> <option>country</option> </select> </div> <div class="col-md-4"> <select class="form-control" id="regions"> <option>regions</option> </select> </div> </div> <div class="row"> <div class="col-md-4"> <button type="button" onclick="button1_click()" id="searchinfo" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> search info</button> </div> </div> <!-- information table--> <div class="table-responsive"> <table id="mytable" class="table table-bordered"> </table> </div> </form> </body> </html>
and aspx.cs code behind:
using mssqlconnector; using system; using system.collections.generic; using system.data; using system.data.sqlclient; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; namespace webapplication1.eyeofheaven { public partial class searchcustomer : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void button1_click(object sender, eventargs e) { response.write("<script>alert('data not found.');</script>"); } } }
i want display alert('data not found.') in search info button. error in console "uncaught reference error:button1_click not defined". have no idea makes code have error. or maybe alert message not valid c# code? called function button1_click in code:
<button type="button" onclick="button1_click()" id="searchinfo" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> search info</button>
please i'm new c# language , i'm adapting following syntax , format.
your button not defined @ server side. need use runat = "server"
button , change onclick
event onserverclick
below
<button type="button" id="searchinfo" runat="server" onserverclick="button1_click" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> search info</button>
instead use asp.net asp:button control below:
<asp:button id="searchinfo" runat="server" onclick="button1_click" cssclass="btn btn-primary" text="search info" />
Comments
Post a Comment