Question Overview: I am creating an application in which I have a html select list from where I select a category and from that category I get items and there images using ajax webmethod.
Problem Overview: I faced many 500 error in ajax linq to sql and fix it. But now I am working on ado.net application and The problem which I was facing is When I select a category from select list(catlist) its shows me error from here error: function (xhr) { alert(xhr.status);}
.
[ArgumentException]: Unknown web method elist. Parameter name: methodName at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) .
How can I fix this error. I thought I briefly describe my question.
Default.Aspx Code Overview:
Below is my HTML
<table>
<tr>
<td>
<select id="catlist" runat="server" onchange="getImageUrl()"></select>
</td>
<td></td>
</tr>
<tr>
<td>
<img id="imgload" width="180" height="100" src="" alt="No Image Found" />
</td>
<td>
<ul>
<li>Description</li>
<li>Loreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum IspumLoreum Ispum</li>
</ul>
</td>
</tr>
</table>
Below is my Javascript Function
function getImageUrl() {
var catid = $("#catlist")[0].value;
$.ajax({
url: "Default.aspx/elist",
data: { catId: catid },
contentType: "Application/json; charset=utf-8",
responseType: "json",
method: "POST",
success: function (response) {
alert(response.d);
},
error: function (xhr) {
alert(xhr.status);
},
Failure: function (response) {
alert(response);
}
});
}
Default.Aspx.cs Code Overview:
Below is my custom class
public class events
{
public string EVE_NAME { get; set; }
public string EVE_IMG_URL { get; set; }
public string EVE_DESCRIPTION_SHORT { get; set; }
}
Below is the Datatable method
private static DataTable dt2(int catId)
{
DataTable dataTable = new DataTable();
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=EVENT;Persist Security Info=True;User ID=sa;Password = 123");
string query = "sp_view";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@catID", SqlDbType.Int).Value = catId;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dataTable);
return dataTable;
}
Below is the WebMethod
[WebMethod]
private static List<events> elist(int catId)
{
List<events> eve = new List<events>();
eve = (from DataRow row in dt2(catId).Rows
select new events
{
EVE_NAME = row["EVE_NAME"].ToString(),
EVE_IMG_URL = row["EVE_IMG_URL"].ToString(),
EVE_DESCRIPTION_SHORT = row["EVE_DESCRIPTION_SHORT"].ToString(),
}).ToList();
return eve;
}
NOTE: Database column names and events class properties names are same.