Asp.net JQUERY,以防我不想使用更新面板。那么在哪种情况下我应该使用JSON和JQUERY呢?如果您不想使用更新面板,您可能会像上面的示例一样使用JQUERY,但您可能无法使用GridView并绑定到它。相反,您可能需要让GetCustomer方法返回一些ht
Asp.net JQUERY,以防我不想使用更新面板。那么在哪种情况下我应该使用JSON和JQUERY呢?如果您不想使用更新面板,您可能会像上面的示例一样使用JQUERY,但您可能无法使用GridView并绑定到它。相反,您可能需要让GetCustomer方法返回一些ht,asp.net,jquery,ajax,web-services,json,Asp.net,Jquery,Ajax,Web Services,Json,JQUERY,以防我不想使用更新面板。那么在哪种情况下我应该使用JSON和JQUERY呢?如果您不想使用更新面板,您可能会像上面的示例一样使用JQUERY,但您可能无法使用GridView并绑定到它。相反,您可能需要让GetCustomer方法返回一些html,然后使用jQuery将该html添加到页面中。 [WebMethod] private void GetCustomer( string NoOfRecords) { string connString = "Data Sour
JQUERY,以防我不想使用更新面板。那么在哪种情况下我应该使用JSON和JQUERY呢?如果您不想使用更新面板,您可能会像上面的示例一样使用JQUERY,但您可能无法使用GridView并绑定到它。相反,您可能需要让GetCustomer方法返回一些html,然后使用jQuery将该html添加到页面中。
[WebMethod]
private void GetCustomer( string NoOfRecords)
{
string connString = "Data Source=Something;Initial Catalog=AdventureWorks;Trusted_Connection=True;";
SqlConnection sCon = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Sales.Customer WHERE CustomerID < '" + NoOfRecords+ "' ", sCon);
DataSet ds = new DataSet();
da.Fill(ds);
GvDetails.DataSource = ds.Tables[0];
GvDetails.DataBind();
}
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<asp:Button ID="btnShow" runat="server" Text="Sow Records without PostBack" />
<asp:GridView ID="GvDetails" runat="server">
</asp:GridView>
</div>
<script language="javascript" type="text/javascript">
var txtID = document.getElementById('txtValue');
$.ajax({
type: "POST",
url: "Default.aspx/GetCustomer",
data: "{Seconds:'" + txtID +"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
alert(response);
}
});
</script>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txtValue" runat="server" CssClass="value"></asp:TextBox>
<asp:Button ID="btnShow" runat="server" CssClass="buttonshow" Text="Sow Records without PostBack" />
</div>
<script language="javascript" type="text/javascript">
//attach event to click event of button with class of 'buttonshow'.
$('.buttonshow').click(function()
{
//get value of textbox with class 'value'
var NoOfRecords = $('.value').val();
//Call GetCustomer method, pass NumberOfRecords, and define the onsuccess and onerror functions.
PageMethods.GetCustomer(
NoOfRecords,
function(result) {
alert('success:' + result);
},
function(result) {
alert('error:' + result.get_message());
});
});
</script>
<asp:GridView ID="GvDetails" runat="server">
</asp:GridView>