RouteData.Values[“xxx”] generates error inside asp.net user Control

Limasnisill

New Member
I am trying to update my asp.net webform based website to use Routing feature but i am failing to fix one error inside userControl.ascx.I can access query string value in main page using \[code\]RouteData.Values["language"].ToString()\[/code\] but same fails when i need to use the query string value inside a user control.I tried even using \[code\]HttpContext.Current.Request.RequestContext.RouteData.Values["language"].ToString();\[/code\]But no luck. Below is the code sample where i am trying to catch the querystring\[code\]int LangID = 1;int ArticleID = 0;int PageID = 0;int IssueID = 0;int CategoryID = 0;string language = string.Empty; if (string.IsNullOrEmpty(Request["PageID"])) { language = HttpContext.Current.Request.RequestContext.RouteData.Values["language"].ToString(); LangID = Helper.GetLanguageID(language); ArticleID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["aid"].ToString()); PageID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["PageID"].ToString()); IssueID = int.Parse(HttpContext.Current.Request.RequestContext.RouteData.Values["issue"].ToString()); } else { language = Request["language"]; LangID = Helper.GetLanguageID(language); ArticleID = int.Parse(Request["aid"]); PageID = int.Parse(Request["PageID"]); IssueID = int.Parse(Request["issue"]); }\[/code\]I am getting following error for this statement\[code\]language = HttpContext.Current.Request.RequestContext.RouteData.Values["language"].ToString();\[/code\]ERROR MESSAGE:\[code\]System.NullReferenceException was caught Message=Object reference not set to an instance of an object. Source=App_Web_odw0cnkk\[/code\]I would appreciate help in this regarding or how to get around this problem
 
Back
Top