Я хочу получить доступ к управлению asp через ajax.Пояснение: я хочу вызвать функцию c # через ajax.Эта функция c # изменяет текст нескольких меток с различными условиями.
Пожалуйста, проверьте следующий код.
<input id="btnSilverGetPrice2" class="btn btn-next btn-fill btn-success btn-wd" type="button" value="Get Price" />
<script type="text/javascript">
function CheckCode(val) {
$.ajax({
type: "GET",
url: "Premium-Membership.aspx/FCheckCode",
data: { 'name': val },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
$("#btnSilverGetPrice2").click(function () {
CheckCode();
})
function OnSuccess(response) {
alert(response.d);
}
</script>
Код C #
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
public static string FCheckCode()
{
Main_Website_SignIn obj = new Main_Website_SignIn();
string ans=obj.trial();
return ans;
}
public string trial()
{
try
{
if (Session["LUSER"].ToString() == "Jobseeker")
{
if (DropDownListSilver.SelectedValue == "6")
{
lblShowRegularPrice.Text = "500/6 Months";
lblShowPopularPrice.Text = "1000/6 Months";
lblShowPlatinumPrice.Text = "1500/6 Months";
lblSilverPrice.Text = "500";
lblGoldPrice.Text = "1000";
lblPlatinumPrice.Text = "1500";
}
}
}
catch (Exception){}
return "working";
}
Сообщение успешно возвращено, но текст меткине изменено.