重複の可能性:
WebMethod からコード ビハインド関数にアクセスする
私はJsonを介して呼び出している次のWebMethodを持っています。その正常に動作します。
[System.Web.Services.WebMethod]
public static string CheckUserName(string userName)
{
string returnValue = string.Empty;
try
{
string consString = ConfigurationManager.AppSettings["cn"].ToString();
SqlConnection conn = new SqlConnection(consString);
SqlCommand cmd = new SqlCommand("UsernameCheck", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", userName.Trim());
conn.Open();
returnValue = cmd.ExecuteScalar().ToString();
conn.Close();
}
catch
{
returnValue = "error";
}
return returnValue;
}
しかし、ご存知のように、静的関数のページ コントロールとコード ビハインド関数にアクセスすることはできません。
しかし、ここでは WebMethod のコード ビハインド関数にアクセスする必要があります。すなわち
public void test()
{
}
Webmethod の「テスト」機能にアクセスするにはどうすればよいですか。テスト機能では、2 つのリピーター コントロールとデータテーブルを使用しました。
ありがとうございました。