0

i want to access code behind when I clicked on a J Query Button , like when i Clicked on a ASP Button . there are some code for this purpose like this .

jQuery.ajax({
    type: "POST",
    url: "edit.aspx/yourmethodname",
    data: "{yourmethodparam:" + somevar + "}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(response) {
        alert(response.d);
    }
error: function(err, response) {
    alert("error");
}
});

But for this code we have to use static method ... and in static method i can't access object's like Textbox1.text and so on... i want when i clicked on a jquery button it worked exactly like a asp Button . and i want the jquery button be in Update Panel to avoid of refreshing page i'm very pleased if anyone can help me ...

4

1 回答 1

1

步骤 1) 在您的 .aspx 页面中添加一个文本框和一个按钮

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="myButtonClick" runat="server"  OnClick="myButtonClick_Click"Text=" "  />

第 2 步)为点击事件编写所需的代码隐藏函数

public void myButtonClick_Click(Object sender, EventArgs e)
{
    string svar = TextBox1.Text;
    Alert.Show(svar);
}

步骤 3) 在您的 ajax 成功消息中从 jquery 调用按钮单击事件

               success: function (response) {

                    $("[id$='_myButtonClick']").trigger('click');

                },

有了这个,您也可以完成 jquery ajax 要求(如果有)以及按钮单击事件要求背后的代码。

享受锐化 C. 干杯。

于 2013-03-02T08:06:46.553 回答