在内容页面中,我有一个文本框和一个按钮。在按钮单击事件上,我想显示一个gridview,这个gridview有一些javaScript用于响应行为。来自Gridview我也在内容页面中使用了ModelPopupExtender(Ajax)。
Page指示:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true"
CodeBehind="UpdateUser.aspx.cs" Inherits="WirelessLCDdisplay.AdminPages.UpdateUser" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
JavaScript:
<script src="../JavaScript/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
<!-- // building select nav for mobile width only -->
$(function () {
// building select menu
$('<select />').appendTo('nav');
// building an option for select menu
$('<option />', {
'selected': 'selected',
'value': '',
'text': 'Choise Page...'
}).appendTo('nav select');
$('nav ul li a').each(function () {
var target = $(this);
$('<option />', {
'value': target.attr('href'),
'text': target.text()
}).appendTo('nav select');
});
// on clicking on link
$('nav select').on('change', function () {
window.location = $(this).find('option:selected').val();
});
});
// show and hide sub menu
$(function () {
$('nav ul li').hover(
function () {
//show its submenu
$('ul', this).slideDown(150);
},
function () {
//hide its submenu
$('ul', this).slideUp(150);
}
);
});
//end
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable = no">
<link href="../css/basic.css" rel="stylesheet" type="text/css" />
<script src="../JavaScript/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="../JavaScript/jquery.responsivetable.js" type="text/javascript"></script>
<script src="../JavaScript/jquery.responsivetable.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
setupResponsiveTables();
});
function setupResponsiveTables() {
$('.responsiveTable1').responsiveTable({
staticColumns: 2,
scrollRight: false,
scrollHintEnabled: true,
scrollHintDuration: 3000
});
}
</script>
TextBox和Button:
<p class="contact">
<label for="username">
Username</label></p>
<asp:TextBox ID="txtUname" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidatorusername" runat="server" ErrorMessage="User Name required"
Text="*" ControlToValidate="txtUname" ForeColor="Red">
</asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnUserDetails" runat="server" Text="Button"
onclick="btnUserDetails_Click1" />
<asp:Button ID="btnReset" runat="server" Text="Reset" class="buttom" CausesValidation="False"
OnClick="btnReset_Click" />
onClick事件背后的代码:
protected void btnUserDetails_Click1(object sender, EventArgs e)
{
BindGridData();
}
private void BindGridData()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select Username,FirstName,LastName,Email,PhNo,Designation,Department,RollId from tblEmployees where Username=@Username", con);
cmd.Parameters.AddWithValue("@Username", txtUname.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
for (int intCount = 0; intCount < ds.Tables[0].Rows.Count; intCount++)
{
if ((Convert.ToString(ds.Tables[0].Rows[intCount].ItemArray[7])) == "0")
{
ds.Tables[0].Rows[intCount].ItemArray[7] = "User";
}
else
{
ds.Tables[0].Rows[intCount].ItemArray[7] = "Admin";
}
}
da.Fill(ds);
gvUserDetails.DataSource = ds;
gvUserDetails.DataBind();
}
**
我的onClick =“btnUserDetails_Click1”事件并非火灾 它背后的原因是什么?
答案 0 :(得分:1)
尝试将onclick更改为OnClick
<asp:Button ID="btnUserDetails" runat="server" Text="Button"
OnClick="btnUserDetails_Click1" />
答案 1 :(得分:0)
在asp.net中有两种类型的按钮事件 'onclick'
和 'OnClick'
。
onclick
:这个曾经火的javascript函数。
OnClick
:如果我们添加runat =&#34; server&#34;按钮上的标签。
注意: 1.On Click事件将请求发送到服务器,作为响应执行操作。 2.在客户端点击非常类似于onclick函数,我们用它来编写Javascript ...即执行语句中的语句 客户端没有将其发送到服务器