PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 [RESOLVED] listview problem-VBForums
Results 1 to 12 of 12

Thread: [RESOLVED] listview problem

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Resolved [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:
    1. Protected Sub editButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles editButton1.Click
    2.         Dim FILENAME As String
    3.         Dim objStreamReader As StreamReader
    4.  
    5. If templateListBox.SelectedItem.ToString.StartsWith("QUOTE (TEMP 1)") Then
    6.  
    7.  
    8.             '======================================= LOAD TEMP DATA =====================================
    9.             'Open a file for reading
    10.             FILENAME = Server.MapPath("~\tttt\tttt\tttt\tttttt.txt")
    11.  
    12.             'Get a StreamReader class that can be used to read the file
    13.  
    14.             objStreamReader = File.OpenText(FILENAME)
    15.  
    16.             'Now, read the entire file into a string
    17.  
    18.             Editor1.Content = objStreamReader.ReadToEnd().ToString
    19.  
    20.  
    21.  
    22.             objStreamReader.Close()
    23.  
    24.             '=====================================================================================================
    25.  
    26.         ElseIf templateListBox.SelectedItem.ToString.StartsWith("tttttt (ALL INCLUSIVE)") Then
    27.  
    28. ....

    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

  2. #2
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    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

  3. #3

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: listview problem

    The error is on the follwoing line

    vb Code:
    1. If templateListBox.SelectedItem.ToString.StartsWith("QUOTE (TEMP 1)") Then
    at this point the value of templateListBox.SelectedItem is null


    thx

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,681

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: listview problem

    It seems we don't have "HideSelection" in aspx

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    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

  7. #7

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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:
    1. 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:
    1. <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    2.                           <ContentTemplate>
    3.                               <asp:Panel ID="Panel1" runat="server">
    4.                                   <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
    5.                                   <asp:ListBox ID="templateListBox" runat="server" Height="250px">
    6.                                       <asp:ListItem>QUOTE (TEMP 1)
    7.                                       </asp:ListItem>
    8.                                       <asp:ListItem>QUOTE (ALL INCLUSIVE)</asp:ListItem>
    9.                                       <asp:ListItem>INVOICE (PAID)
    10.                                       </asp:ListItem>
    11.                                       <asp:ListItem>INVOICE (PENDING)</asp:ListItem>
    12.                                       <asp:ListItem>RESERVATION
    13.                                       </asp:ListItem>
    14.                                       <asp:ListItem>OUTSOURCE
    15.                                       </asp:ListItem>
    16.                                       <asp:ListItem>MANIFEST
    17.                                       </asp:ListItem>
    18.                                       <asp:ListItem>BOOKING
    19.                                       </asp:ListItem>
    20.                                       <asp:ListItem>TRIPSHEET
    21.                                       </asp:ListItem>
    22.                                       <asp:ListItem>RECEIPT
    23.                                       </asp:ListItem>
    24.                                       <asp:ListItem>FARMOUTS
    25.                                       </asp:ListItem>
    26.                                   </asp:ListBox>
    27.                                   <br />
    28.                                   <asp:Button ID="editButton1" runat="server" Text="Edit" />
    29.                                   <asp:UpdateProgress ID="UpdateProgress1" runat="server"
    30.                                       AssociatedUpdatePanelID="UpdatePanel1">
    31.                                       <progresstemplate>
    32.                                           <asp:Image ID="Image2" runat="server" ImageUrl="~/images/ajax-loader.gif" />
    33.                                       </progresstemplate>
    34.                                   </asp:UpdateProgress>
    35.                               </asp:Panel>
    36.                           </ContentTemplate>
    37.                           <triggers>
    38.                               <asp:AsyncPostBackTrigger ControlID="editButton1" EventName="Click" />
    39.                           </triggers>
    40.                       </asp:UpdatePanel>

    vb Code:
    1. <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    2.                           <ContentTemplate>
    3.                               <asp:Panel ID="Panel2" runat="server">
    4.                      
    5.                                   <cc1:Editor ID="Editor1" runat="server" Height="342px"
    6.                                       HtmlPanelCssClass="MyHtmlPanel" style="font-size: xx-small"
    7.                                       Width="850px" />
    8.                      
    9.                                   <asp:Button ID="QuoteTemp1saveButton" runat="server" Text="Save Changes" />
    10.                                   <asp:Label ID="Statuslabel" runat="server" Font-Names="Tahoma"
    11.                                       ForeColor="#006600"></asp:Label>
    12.                      
    13.                        </asp:Panel>
    14.                           </ContentTemplate>
    15.                           <triggers>
    16.                               <asp:AsyncPostBackTrigger ControlID="editButton1" EventName="Click" />
    17.                           </triggers>
    18.                       </asp:UpdatePanel>


    thx

  8. #8
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: listview problem

    Hello,

    You have the trigger for both UpdatePanels as the same button.

    Is that what you intended?

    Gary

  9. #9

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    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.
    Attached Images Attached Images   

  10. #10
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    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

  11. #11

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    Re: listview problem

    I finally decided to use a radiobutonlist and now everything works fine

    thx

  12. #12
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    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
  •  



Featured


Click Here to Expand Forum to Full Width