Hi There,

I have a user control that has 2 listmenus populated from a database, 
I want the form to submit when the listmenu are changed which seems 
to happen no problem when the page is on it's own but when I have it 
as user control I get the error "Object reference not set to an 
instance 
of an object. " what am I doing wrong?

Sean

!--- page

<%@ Register TagPrefix="UserControl1" TagName="header" 
Src="includes/_Header.ascx" %>
<%@ Register TagPrefix="UserControl2" TagName="footer" 
Src="includes/_footer.ascx" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1">
<meta name="distribution" content="global">
<meta name="revisit-after" content="14 days">
<meta name="ROBOTS" content="ALL">

<title>title</title>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<form runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <td colspan="2" valign=top><UserControl1:Header 
runat="server" /></td>
  <tr>
    <td width="100" valign=top></td>
    <td width="563" valign=top>content area</td>
  </tr>

 <TR>
<td colspan=2><UserControl2:footer runat="server" /></td>
<td>
</tr>
</table>
</form>
</body>
</html>


!-- user control

<%@ Control Language="vb" EnableViewState="False" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
        
  Public Sub Page_Load(sender as Object, e as EventArgs)
  
        If Not Page.IsPostBack Then
                BindStates()
                LoadCategories()
        Else
                Dim strFormID as Integer
                Dim strSelectedStates as Integer
                Dim strSelectedCategories as Integer
                
                strSelectedCategories = 
lstCategorie.SelectedItem.Value 
                strSelectedStates         =
        lstStates.SelectedItem.Value 
                
                
                        If strSelectedStates <> "0" AND 
strSelectedCategories ="0" Then
                                strFormID = strSelectedStates
                                SendUserToState(strFormID)
                        Elseif strSelectedStates = "0" AND 
strSelectedCategories <> "0" Then       
                                'response.write ("categories")
                                'response.end 
                                strFormID = strSelectedCategories
                                SendUserToCategorie(strFormID)
                        End If
                        
        End If    
  End Sub
  
 Public Function SendUserToState(ByVal strFormID as Integer)
        Select Case strFormID
                Case 1,2,3,4,5,6,7,8,9
                        response.redirect("browselistingsbystate.aspx?
StateID=" & strFormID)
                Case Else
                        'do jack all
        End Select      
 End Function 
 
 Public Function SendUserToCategorie(ByVal strFormID as Integer)
        Select Case strFormID
                Case 6,10,8,7,11,13,9,12
                        response.redirect("browselistings.aspx?
CategoryID=" & strFormID)
                Case Else
                        'do jack all
        End Select      
 End Function 
        
        
 Public Sub BindStates()
   Try
                Dim myConnection as New SqlConnection
(ConfigurationSettings.AppSettings("connectionString"))
                        Const strSQL as String = "SELECT 
LocationID, '...' + Location + '...' AS Location " & _
                                                                
        "FROM tbLocation ORDER BY Location"
                Dim myCommand as New SqlCommand(strSQL, myConnection)
                myConnection.Open()
                Dim objDR as SqlDataReader
                objDR = myCommand.ExecuteReader
(CommandBehavior.CloseConnection)
                        lstStates.DataSource = objDR
                        lstStates.DataBind()
                        lstStates.Items.Insert(0, new ListItem("-- 
Choose a State --","0"))
                
         Catch ex as InvalidCastException
                Status.Text = ex.ToString()
  
      Catch ex As SqlException
         Status.Text = "Database error: " & ex.message
        
      Catch ex As Exception
         Status.Text = "General error: " & ex.message
      End Try
        
  End Sub
  
  
  Public Sub LoadCategories()
         Try
                Dim myConnection as New SqlConnection
(ConfigurationSettings.AppSettings("connectionString"))
                        Const strSQL as String = "SELECT 
CategoryID, '...' + CategoryDesc + '...' AS CategoryDesc " & _
                                                                
        "FROM tblProductCategories ORDER BY CategoryDesc"
                Dim myCommand as New SqlCommand(strSQL, myConnection)
                myConnection.Open()
                Dim objDR as SqlDataReader
                objDR = myCommand.ExecuteReader
(CommandBehavior.CloseConnection)
                        lstCategorie.DataSource = objDR
                        lstCategorie.DataBind()
                        lstCategorie.Items.Insert(0, new ListItem("-- 
Choose a Category --","0"))
                
                Catch ex as InvalidCastException
                        Status.Text = ex.ToString()
  
                Catch ex As SqlException
                        Status.Text = "Database error: " & ex.message
        
                Catch ex As Exception
                        Status.Text = "General error: " & ex.message
      End Try
        
        End Sub
  
</script>


    
  
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <tr> 
    <td width="58%"><img src="images/Header.gif" width="441" 
height="47"> </td>
    <td width="42%">
      <div align="right"><font face="Verdana, Arial, Helvetica, sans-
serif" size="1" color="#999999"><br>
        <br>
        Log-in | Join Site | Terms &amp; Conditions | Contact us 
</font></div>
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="5" 
height="20">
  <tr bgcolor="#999999"> 
    <td height="20" width="19%"> 
      <div align="right"><font face="Verdana, Arial, Helvetica, sans-
serif" size="1" color="#FFFFFF">Sell 
        Irrigation equipment :</font></div>
    </td>
    <td height="20" width="18%"> 

        <div align="left"> 
          
        </div>

    </td>
    <td height="20" width="11%"> 
      <div align="right"><font face="Verdana, Arial, Helvetica, sans-
serif" size="1" color="#FFFFFF">Browse 
        :</font></div>
    </td>
    <td height="20" width="14%"> 

        <div align="left">
           <asp:listbox id="lstCategorie" runat="server" Rows="1" 
AutoPostBack="true"
               DataTextField="CategoryDesc" 
DataValueField="CategoryID" />

        </div>

    </td>
    <td height="20" width="11%"> 
      <div align="right"><font face="Verdana, Arial, Helvetica, sans-
serif" size="1" color="#FFFFFF">Browse 
        :</font></div>
    </td>
    <td height="20" width="14%"> 

        <div align="left">
          <asp:listbox id="lstStates" runat="server" Rows="1" 
AutoPostBack="true"
               DataTextField="Location" DataValueField="LocationID" />
        </div>

    </td>
    <td height="20" width="17%"> 
      <div align="center"><font face="Verdana, Arial, Helvetica, sans-
serif" size="1" color="#FFFFFF"> 
        Search Site </font></div>
    </td>
  </tr>
</table>

  
        <asp:Label id="status" runat="server"></asp:Label>
        






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to