Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Object reference not set to an instance of an object.

Posted on 2012-09-21
5
Medium Priority
?
728 Views
Last Modified: 2012-10-15
I have the following scenario. Users can select values from a drop down list and when the selected value changes it triggers the ddlMovement_SelectedIndexChanged. However I am getting the "Object reference not set to an instance of an object." error on line rEShipper.Visible = False. Can someone assist please?

Protected Sub ddlMovement_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlMovement As DropDownList = fvShip.FindControl("ddlMovement")
        Dim rEShipper As TableRow = fvShip.FindControl("rEShipper")

              If ddlMovement.SelectedValue = "ADDITIONAL RECOVERY" Then
            rEShipper.Visible = False
                  Else
            rEShipper.Visible = True
                  End If
    End Sub

Open in new window


Which gets triggered by the aspx page:

  <asp:FormView ID="fvShip" runat="server" DataSourceID="sdsShipDetail" CellPadding="0">
                        <EditItemTemplate>
                            <table border="0" id="EditTable">
  <tr>
                                    <td align="left">Type of Movement:</td>
                                    <td align="left"  colspan="4"><asp:DropDownList ID="ddlMovement" SelectedValue='<%# Bind("Movement_Name")%>'  runat="server" DataSourceID="sdsMovement" DataTextField="Movement_Name"
                            DataValueField="Movement_Name" CssClass="form" AutoPostBack="True" OnSelectedIndexChanged="ddlMovement_SelectedIndexChanged">
                        </asp:DropDownList>&nbsp;
                        <asp:SqlDataSource ID="sdsMovement" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>"
                            SelectCommand="View_Movement_DD_Dell" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
                                    </td>
                                </tr>
<tr>
                                    <td>
                                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" ValidationGroup="PIRUpdate"  
                                            CommandName="Update" Text="Update" ></asp:LinkButton>
                                    </td>
                                    <td  colspan="4">
                                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Cancel"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <div>
                            </div>
                        </EditItemTemplate>

Open in new window

0
Comment
Question by:JessyRobinson1234
5 Comments
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 38420988
It would seem that

Dim rEShipper As TableRow = fvShip.FindControl("rEShipper")

is not returning anything. (null)

I can't see a control called rEShipper in the mark up posted
0
 

Author Comment

by:JessyRobinson1234
ID: 38421000
Sorry I should have put that in there as well. Here's the aspx code reposted

<asp:FormView ID="fvShip" runat="server" DataSourceID="sdsShipDetail" CellPadding="0">
                        <EditItemTemplate>
                            <table border="0" id="EditTable">
  <tr>
                                    <td align="left">Type of Movement:</td>
                                    <td align="left"  colspan="4"><asp:DropDownList ID="ddlMovement" SelectedValue='<%# Bind("Movement_Name")%>'  runat="server" DataSourceID="sdsMovement" DataTextField="Movement_Name"
                            DataValueField="Movement_Name" CssClass="form" AutoPostBack="True" OnSelectedIndexChanged="ddlMovement_SelectedIndexChanged">
                        </asp:DropDownList>&nbsp;
                        <asp:SqlDataSource ID="sdsMovement" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>"
                            SelectCommand="View_Movement_DD_Dell" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
                                    </td>
                                </tr>
  <tr id="reShipper">
                                    <td align="left">Shipper Nbr / Return to Plant / Sort / IP:</td>
                                    <td align="left"  colspan="4"><asp:TextBox ID="txtShipper" runat="server" CssClass="form" Width="200px" Text='<%# Bind("Ship_Nbr") %>'></asp:textbox>
                                    </td>
                                </tr>
<tr>
                                    <td>
                                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" ValidationGroup="PIRUpdate"  
                                            CommandName="Update" Text="Update" ></asp:LinkButton>
                                    </td>
                                    <td  colspan="4">
                                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Cancel"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <div>
                            </div>
                        </EditItemTemplate> 

Open in new window

0
 
LVL 8

Expert Comment

by:Wiesje
ID: 38421016
I would assume it has to do with the fact that in the aspx code it is called reShipper as ID, but in  your code you are looking for rEShipper.
0
 

Author Comment

by:JessyRobinson1234
ID: 38421090
I changed it to be rEShipper but same error...
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 2000 total points
ID: 38421175
The html table row  <tr id="reShipper"> is not an asp .net control.
Using findcontrol may not be an option.

If you converted the html table to an asp:table, with a runat='server' attribute, you should have more success and should be able to reference the tablerow using:
    ' asp:table e.g.
    <asp:Table ID="thetable" runat="server" >
      <asp:TableRow ID="therow" runat="server">
        <asp:TableCell ID="thecell" runat="server" Text="sometext"></asp:TableCell> 
      </asp:TableRow>
    </asp:Table>

    Dim objrEShipper As TableRow = Nothing
    objrEShipper = CType(Me.fvShip.FindControl("reShipper"), TableRow) ' case matters too

    If objrEShipper IsNot Nothing Then
      With objrEShipper
        If ddlMovement.SelectedValue = "ADDITIONAL RECOVERY" Then
          .Visible = False
        Else
          .Visible = True
        End If
        .Dispose()
      End With
    End If

Open in new window

Alan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question