嗨請檢查我想獲得代碼後面的點擊事件,因爲我正在使用母版頁概念,並且我在此頁面中有一個子窗體,我有ContentPlaceHolder,My按鈕「btnSubmit」這是一個在GridView下的鏈接按鈕。我想要加載圖像,當我點擊btnSubmit按鈕。請檢查並幫助。如何使用jquery獲取c#代碼中的點擊事件
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
function ShowProgress() {
setTimeout(function() {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height()/2 - loading[0].offsetHeight/2, 0);
var left = Math.max($(window).width()/2 - loading[0].offsetWidth/2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function() {
ShowProgress();
});
aspx頁面..
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Journal" HeaderText="Customer Id" />
<asp:BoundField DataField="ISBN" HeaderText="Contact Name" />
<asp:BoundField DataField="Status" HeaderText="City" />
<asp:TemplateField HeaderText="Btn">
<ItemTemplate>
<asp:Button ID="btnSubmit" runat="server" Text="Load Customers"
OnClick="btnSubmit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div class="loading" align="center">
Downloading Files. Please wait<br />
<br />
<img src="loader.gif" alt="" />
</div>
</asp:Content>
在CS頁面。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string script = "$(document).ready(function() { $('[id*=btnSubmit]').click(); });";
ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
}
}
只要確保您使用的是提交按鈕的正確標識,因爲id是使用contentplaceholder id.Description在瀏覽器中進行呈現並使用它。 – Mairaj 2014-08-27 07:59:14