I am working on asp.net application. In this application i have used Url rewrinting method to show pages in the browser. Whenever any wants to edit any record i have checked whether the 'ID' to be edit is null or not as:
if (Page.RouteData.Values["ID"] != null)
{
}
If this condition will be true then it means the wants to edit the record of id passed through
Page.RouteData.Values["ID"]
from the form all the data is being displayed. and user select any one of them.the above "if" condition works fine when it is not used in any webMethod but it is used in the webmethod the error comes.
My webMethod is
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(e)]
public static string SaveData(string Category,string SubCategory,string ProductType)
{
try
{
ProductBrand objBrand = new ProductBrand();
DataTable dt = new DataTable();
ProductType objProductType = new ProductType();
objProductType.SubCategoryID = Convert.ToInt64(SubCategory);
objProductType.ProductTypeName = ProductType;
if (Page.RouteData.Values["ID"] != null)
{
objProductType.TypeID = Convert.ToInt64(Page.RouteData.Values["ID"].ToString());
objProductType.Flag = "U";
else
{
dt = new ProductType().SelectByCategory(objProductType.SubCategoryID, objProductType.ProductTypeName);
if (dt.Rows.Count > 0)
{
objProductType.Flag = "D";
}
else
{
objProductType.Flag = "I";
}
}
if (objProductType.Flag.Equals("D"))
{
objBrand.BrandID = 2;
}
else
{
int retval = new ProductType().Insert(objProductType);
if (retval > 0)
{
objBrand.BrandID = 1;
}
else
{
objBrand.BrandID = 0;
}
}
return objBrand.BrandID.ToString();
}
catch (Exception ex)
{
throw (ex);
}
}
The above webmethod has been written to insert data into datbase using jquery. In the above webmethod in the statement "if (Page.RouteData.Values["ID"] != null)" the error is showing as
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.RouteData.get'
But when i use the above condition outside of webmethod this error is not coming. Please help me someone here.