|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Asp.net Mobile controls + NullReference Exception
Hi,
I am defining DeviceSpecific region in a ObjectList and trying to have header for each paginated page, header contains two labels whose text will set be after the results from the database like total number of records. When I try to execute the following code I am getting Object reference nullexception. I couldnt understand, could anyone please tell me, why I am getting that. Here is my code for aspx and code behind file. <mobile:Form Runat=server ID="form" Paginate=True> <mobile:ObjectList ID="rptPublications" Runat="server" OnPreRender="rptChecking_PreRender"> <DeviceSpecific ID="dspChkAcct" Runat="server"> <Choice> <HeaderTemplate> <mobile:Label ID="hitResults" Runat=server Font-Bold=True Font-Size=Normal StyleReference=title Text=""></mobile:Label> <mobile:Label ID="pageIndex" Runat=server Font-Size=Small Text=""></mobile:Label> </HeaderTemplate> <ItemTemplate> <mobile:Link ID="aViewTopic" Runat="server" Font-Size=Small NavigateUrl="" BreakAfter=True/> <mobile:Label ID="tpcDetails1" Runat=server Font-Size=Small BreakAfter=True></mobile:Label> <mobile:Label ID="tpcDetails2" Runat=server Font-Size=Small BreakAfter=True></mobile:Label> </ItemTemplate> <SeparatorTemplate><br /></SeparatorTemplate> </Choice> </DeviceSpecific> </mobile:ObjectList> </mobile:Form> Code Behind file protected void rptChecking_PreRender(object sender, EventArgs e) { pageCount = form.PageCount.ToString(); ((System.Web.UI.MobileControls.Label)rptPublications.Controls[0].FindControl("hitResults")).Text = "Search results for - " + searchKey + " (" + rptPublications.Items.Count + ")"; ((System.Web.UI.MobileControls.Label)rptPublications.Controls[1].FindControl("pageIndex")).Text = "Showing Page" + currentPage + " of " + pageCount + ", Total Records: " + results.ChildNodes.Count; foreach (ObjectListItem item in rptPublications.Items) { XmlNode node = (XmlNode)item.DataItem; if (node != null) { Label pubTitle = (Label)item.FindControl("pubTitle"); Link aViewTopic = (Link)item.FindControl("aViewTopic"); Label tpcDeatils1 = (Label)item.FindControl("tpcDetails1"); Label tpcDeatils2 = (Label)item.FindControl("tpcDetails2"); string pubId = node.Attributes["PubId"].Value; string title = node.Attributes["Title"].Value; string topicHeading = node.SelectNodes("//TopicHeading").Item(item.Index).InnerText; string topicID = node.SelectNodes("//TopicID").Item(item.Index).InnerText; string topicType = node.SelectNodes("//TopicType").Item(item.Index).InnerText; string author = node.SelectNodes("//Author").Item(item.Index).InnerText; string views = node.SelectNodes("//NoOfViews").Item(item.Index).InnerText; string comment = node.SelectNodes("//NoOfComments").Item(item.Index).InnerText; string mDate = node.SelectNodes("//ModifiedDate").Item(item.Index).InnerText; string topicLink = "/HNMobileApp/topic.aspx?tid=" + topicID; aViewTopic.Text = topicHeading; aViewTopic.NavigateUrl = topicLink; tpcDeatils1.Text = "Comments: " + comment + " | " + "Views: " + views; tpcDeatils2.Text = "By: " + author + " on " + mDate; } } } Thanks Aruna.G |
|
#2
|
||||
|
||||
|
Do you really need to ask twice?
If you debug line-by-line you will find the problem. You have a variable somewhere you are trying to use before the variable has been populated. If you debug, the application will crash on the line that is causing you the problem. Give that a blast first and come back and let us know which line it is. |
|
#3
|
||||
|
||||
|
Please use [asp]asp tags[/asp] or similar to highlight your code.
__________________
Cheers, Jamie # skiFFie | Home of the 'accessibility module' for Drupal # Jamie Burns [me] Accessibility Module [drupal] # guidelines | search | wap resources | not getting help | fold to cure __________________ Let the might of your compassion arise to bring a quick end to the flowing stream of the blood and tears ..... Please hear my anguished words of truth. ![]() __________________ |
|
#4
|
|||
|
|||
|
Asp.net Mobile controls + NullReference Exception
Its very urgent for me. So I posted in two forums. For debugging I am completly using asp.net mobile control forms so I couldnot debug my code I can only run my code. I coded in ascx form and copied to aspx page and running my application in aspx page. If you have any idea how to debug this Please tell me.
Quote:
|
|
#5
|
||||
|
||||
|
Quote:
In 2005, goto the Debug menu, Select 'Attach To Process...', Find 'aspnet_wp.exe' in the process list - select it and click 'Attach'. That's one way, another is to click the green 'play' button. |
|
#6
|
|||
|
|||
|
Asp.net Mobile controls + NullReference Exception
Hi,
I have successfully debug my code, I found that the mobile control inside the Choice cannot be found. Even I tried with the simple code like below and its also not finding my mobile control. Do anyone have idea? <mobile:Form id="external_link" runat="server"> <mobile:ObjectList ID="externalPublications" Runat=server OnItemDataBind="externalPublications_ItemDataBind"> <DeviceSpecific ID="dspChkPub" Runat=server> <Choice> <ItemTemplate> <mobile:Label ID="topictitle" Runat=server /> </ItemTemplate> </Choice> </DeviceSpecific> </mobile:ObjectList> </mobile:Form> Thanks, Aruna.G |
|
#7
|
||||
|
||||
|
Hi again,
I haven't done any mobile application development myself, but read this from MS about DeviceSpecific Class. It looks like a pretty good example and uses the FindControl method. Give that a blast. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Mobile Programming > Asp.net Mobile controls + NullReference Exception |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|