this is my HTML
Code
div>Code
asp:TextBox ID="TextBox1" runat="server">/asp:TextBox>Python
input type="button" id="Button2" runat="server" value="Button" />Code
/div>Code
[WebMethod()]Code
[ScriptMethod()]Code
public static void myMethod(string text)Code
{Code
Label1.text=text;Code
}Code
$(document).ready(function () {Code
$("#Button2").click(function () {Code
var text = $("#TextBox1").val();Code
$.ajax({Code
type: "POST",Code
url: "WebForm1.aspx/myMethod",Code
data: "{ text: '" + text + "'}",Code
contentType: "application/json; charset=utf-8",Code
dataType: "json",Code
async: "true",Code
cache: "false",Code
success: function (msg) {Code
alert("success");Code
},Code
Error: function (x, e) {Code
// On ErrorCode
}Code
});Code
});Code
});Code
"control1" runat="server" />Code
Register TagPrefix="UC" TagName="userControl " src="~/Controls/Mycontrol.ascx" %>Code
i tried url value(s) like url: "Mycontrol.ascx/myMethod",Code
url: "WebForm1.aspx/Mycontrol.ascx/myMethod",but still am unable to get it

Mangesh GRank #294 · 8.6K reputationPosted Jan 6, 2017, 2:36 AM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 4, 2017, 4:32 AM EST
Chetan RanpariyaRank #1,852 · 801 reputationPosted Jan 4, 2017, 5:02 AM EST
Madhav170 reputationPosted Jan 4, 2017, 7:01 PM EST
url: "WebForm1.aspx/myMethod1",
Mangesh GRank #294 · 8.6K reputationPosted Jan 4, 2017, 7:24 PM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 4, 2017, 7:32 PM EST
Madhav170 reputationPosted Jan 4, 2017, 7:32 PM EST
Madhav170 reputationPosted Jan 4, 2017, 7:51 PM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 4, 2017, 9:38 PM EST
Madhav170 reputationPosted Jan 5, 2017, 1:07 AM EST
please check the attchment once
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Jan 5, 2017, 3:38 AM EST
Madhav170 reputationPosted Jan 5, 2017, 3:50 AM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 5, 2017, 10:18 AM EST
/* Method shoud be static so as to make it as WebMethod
* We are doing AJAX POST to the WebMethod so it has to be somewhere where we can post the data
* User Controls are part of the WEB PAGE they are not rendered seprately
* Dont try to access the Control values In the WEB METHOD as Being static everything u access has to be the static an
* controls are not static.........
*/
Madhav170 reputationPosted Jan 5, 2017, 6:38 PM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 5, 2017, 8:21 PM EST
Mangesh GRank #294 · 8.6K reputationPosted Jan 5, 2017, 10:54 PM EST
Madhav170 reputationPosted Jan 5, 2017, 11:40 PM EST
actauly i was facing some other issue with user control and to avoid resolve that issue many people suggest me to use ajax call,
my issue was very simple and that is like,when i am clicking on button from user control that was reloading/refresh the entire page.
and there is one requirement which could be done by controler because the same thing gone be use on more thatn one master page and master page not have any .cs page where i could write any simple or webmethod.
Madhav170 reputationPosted Jan 6, 2017, 3:51 AM EST
really thanks man