-
Jun 24th, 2011, 04:16 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] listview problem
Hi,
i'm having a little problem with my page.
On my page i have two update panels, one listbox, one button and one ajax editor
one update panel for the listbox and button, another one for the editor.
my code look slike this
vb Code:
Protected Sub editButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles editButton1.Click Dim FILENAME As String Dim objStreamReader As StreamReader If templateListBox.SelectedItem.ToString.StartsWith("QUOTE (TEMP 1)") Then '======================================= LOAD TEMP DATA ===================================== 'Open a file for reading FILENAME = Server.MapPath("~\tttt\tttt\tttt\tttttt.txt") 'Get a StreamReader class that can be used to read the file objStreamReader = File.OpenText(FILENAME) 'Now, read the entire file into a string Editor1.Content = objStreamReader.ReadToEnd().ToString objStreamReader.Close() '===================================================================================================== ElseIf templateListBox.SelectedItem.ToString.StartsWith("tttttt (ALL INCLUSIVE)") Then ....
for some item in my listbox the code works fine, but for some, it shows an error "Object reference not set to an instance of an object." and indicate selected item value is null . I'm not sure why this is happening.
Thanks
-
Jun 24th, 2011, 06:40 AM
#2
Re: listview problem
Hello,
Which line is it exactly that is causing the error?
Have you set a breakpoint in that line and identified which object is null/Nothing? If so, what is it?
Gary
-
Jun 24th, 2011, 06:42 AM
#3
Thread Starter
Frenzied Member
Re: listview problem
The error is on the follwoing line
vb Code:
If templateListBox.SelectedItem.ToString.StartsWith("QUOTE (TEMP 1)") Then
at this point the value of templateListBox.SelectedItem is null
thx
-
Jun 24th, 2011, 07:04 AM
#4
Re: listview problem
That means nothing in the listview has been selected... one thing to look for, I don't know if the ASP control has this same issue as the winforms one does, but look for a property... I think it's called "HideSelection" ... the description is along the lines of "Hides the selection when control looses focus" .. it defaults to true for some reason... Set it to false. I've found that sometimes you select something, then go to click a button, since the LV looses focus, the selection becomes hidden and the SelectedItem becomes nothing... I don't get it... but changing that setting usually helps. At least it does with WinForms...
-tg
-
Jun 24th, 2011, 08:40 AM
#5
Thread Starter
Frenzied Member
Re: listview problem
It seems we don't have "HideSelection" in aspx
-
Jun 24th, 2011, 11:53 AM
#6
Re: listview problem
Sounds to me like you have some form of timing issue going on here.
For instance, it could be possible that in between you selecting the Item in the ListView, and mousing the mouse to click the button, an "update" has occured, which essentially resets the SelectedItem property.
One way to stop this happening would be to first check that the SelectedItem property isn't null/Nothing, before accessing it's members, although, this is nothing more than a guard against the underlying problem.
Without seeing more of your code, and perhaps a working sample, it is difficult to say what else could be going on with your page.
I would recommend using Fiddler while you are testing your page, get it to happen again, and then look to see what Requests/Responses were happening at the time.
Gary
-
Jun 24th, 2011, 02:53 PM
#7
Thread Starter
Frenzied Member
Re: listview problem
Hi,
This is my page code, the code works only with the 1st and third item only (starting from 0).
I tried to implement a check of the value
vb Code:
If templateListBox.SelectedItem.Text <> "" Then
But again it shows the same error on this line of code. it's suggesting that i declare the instance as new
vb Code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Panel ID="Panel1" runat="server"> <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /> <asp:ListBox ID="templateListBox" runat="server" Height="250px"> <asp:ListItem>QUOTE (TEMP 1) </asp:ListItem> <asp:ListItem>QUOTE (ALL INCLUSIVE)</asp:ListItem> <asp:ListItem>INVOICE (PAID) </asp:ListItem> <asp:ListItem>INVOICE (PENDING)</asp:ListItem> <asp:ListItem>RESERVATION </asp:ListItem> <asp:ListItem>OUTSOURCE </asp:ListItem> <asp:ListItem>MANIFEST </asp:ListItem> <asp:ListItem>BOOKING </asp:ListItem> <asp:ListItem>TRIPSHEET </asp:ListItem> <asp:ListItem>RECEIPT </asp:ListItem> <asp:ListItem>FARMOUTS </asp:ListItem> </asp:ListBox> <br /> <asp:Button ID="editButton1" runat="server" Text="Edit" /> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> <progresstemplate> <asp:Image ID="Image2" runat="server" ImageUrl="~/images/ajax-loader.gif" /> </progresstemplate> </asp:UpdateProgress> </asp:Panel> </ContentTemplate> <triggers> <asp:AsyncPostBackTrigger ControlID="editButton1" EventName="Click" /> </triggers> </asp:UpdatePanel>
vb Code:
<asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:Panel ID="Panel2" runat="server"> <cc1:Editor ID="Editor1" runat="server" Height="342px" HtmlPanelCssClass="MyHtmlPanel" style="font-size: xx-small" Width="850px" /> <asp:Button ID="QuoteTemp1saveButton" runat="server" Text="Save Changes" /> <asp:Label ID="Statuslabel" runat="server" Font-Names="Tahoma" ForeColor="#006600"></asp:Label> </asp:Panel> </ContentTemplate> <triggers> <asp:AsyncPostBackTrigger ControlID="editButton1" EventName="Click" /> </triggers> </asp:UpdatePanel>
thx
-
Jun 24th, 2011, 03:04 PM
#8
Re: listview problem
Hello,
You have the trigger for both UpdatePanels as the same button.
Is that what you intended?
Gary
-
Jun 24th, 2011, 03:58 PM
#9
Thread Starter
Frenzied Member
Re: listview problem
I tried removing the triggers one by one but still, its not fixing it
i attached screen pics to give u an idea.
-
Jun 25th, 2011, 03:09 AM
#10
Re: listview problem
As has already been said, the only reason that this would happen is if there is no item selected in the ListView.
Did you try using Fiddler as I suggested?
Gary
-
Jul 17th, 2011, 11:00 AM
#11
Thread Starter
Frenzied Member
Re: listview problem
I finally decided to use a radiobutonlist and now everything works fine
thx
-
Jul 17th, 2011, 01:26 PM
#12
Re: [RESOLVED] listview problem
Hey,
Glad to hear that you got it all sorted out.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|