Page_PreRender Firing after ASP Calendar Click

My ASP Calendar won't let me change months because my Page_PreRender is firing after ASP Calendar click.

Is there a way I can make this fire only after a user clicks Submit, and not every time I click on my calendar?


            <script language="vb" runat="server">
          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
               'Put user code to initialize the page here
               If (Not Page.IsPostBack) Then
                    listFoods()
                    FQlist()
               End If
          End Sub
             
          Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
           listFoods()
           FQlist()
                     
    End Sub

         Private Sub listFoods()

                Dim objconn As New SqlConnection("Mystring")
               objconn.Open()
               try
               Dim MemID
            MemID = (Request.Cookies(“sy”)("MemID"))        
               Dim objcmd As New SqlCommand("ChFQ" , objconn)
               objCmd.CommandType = CommandType.StoredProcedure
              Dim retValue As Integer
              objcmd.Parameters.Add("@MemID", SqlDbType.Int).Value = MemID
               Dim retParam As New SqlParameter("@RETURN_VALUE", SqlDbType.Int)
retParam.Direction = ParameterDirection.ReturnValue
objcmd.Parameters.Add(retParam)

objcmd.ExecuteScalar()

retValue = Cint(Cint(objcmd.Parameters("@RETURN_VALUE").Value))
If retValue = 300 then
'no daily Foods
else

Dim dr As SqlDataReader
               dr = objcmd.ExecuteReader()
               Dim currentNick as string = ""
               Dim currentNoNick as string = ""
Dim dt as DataTable = new DataTable()
dt.Columns.Add("HOft")
dt.Columns.Add("FreqID")
dt.Columns.Add("mydate")
dt.Columns.Add("FoodID")
dt.Columns.Add("FoodDesc")
dt.Columns.Add("HMID")
dt.Columns.Add("HMNickName")
dt.Columns.Add("NickDisplay")
dt.Columns.Add("NoNickDisplay")

Do While (dr.Read())
    Dim row as DataRow = dt.NewRow()
 row("HOft")=dr("HOft")
 row("FreqID")=dr("FreqID")
     row("mydate")=dr("mydate")
     row("FoodID")=dr("FoodID")
    row("FoodDesc")=dr("FoodDesc")
         row("HMID")=dr("HMID")
     if   (currentNoNick =("")) and (dr("HMNickName") = ("Please Select"))
    row("NoNickDisplay") = "Anyone's Foods"
        currentNoNick="Anyone"
        elseif (currentNoNick="Anyone")
        row("NoNickDisplay")=""
        end if
        if (currentNick <> dr("HMNickName")) and (dr("HMNickName") <> ("Please Select")) ' if this is the first time this Room has come up
        row("NickDisplay") = dr("HMNickName")+"'s Foods"
        currentNick=dr("HMNickName")
    Else
        row("NickDisplay")=""
    End If
      dt.Rows.Add(row)
Loop
       dataList1.DataSource = dt
       dataList1.DataBind()
       dr.Close
end if
               finally
               objConn.Close()
               objConn.Dispose()
               end try
             
               End Sub
     
Private Sub datalist_item_bind(ByVal sender As Object, ByVal e As DataListItemEventArgs)
              If ((e.Item.ItemType = ListItemType.Item) or ( e.Item.ItemType = ListItemType.AlternatingItem)) Then
                    Dim droplist As DropDownList
                   
                    droplist = CType(e.Item.FindControl("supplierDrop"), DropDownList)
                    Dim objconn As New SqlConnection("Mystring")
                    objconn.Open()
                   
                    try
                   
                    Dim objcmd As New SqlCommand("FQEd", objconn)
                    objCmd.CommandType = CommandType.StoredProcedure
                    Dim dr As SqlDataReader
                    dr = objcmd.ExecuteReader()              
                    droplist.DataSource = dr
                    droplist.DataTextField = "HOft"
                    droplist.DataValueField= "FreqID"
                    droplist.DataBind()
                   
          if not droplist.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "FreqID").ToString()) is nothing then
     droplist.Items.FindByValue(DataBinder.Eval(e.Item.DataItem, "FreqID").ToString()).Selected = True
end if
              dr.Close()
                    finally
                    objConn.Close()
                   objConn.Dispose()
                    end try

               End If
          End Sub
         
         
            </script>
      </HEAD>
      <body>
            
            <br>
            <div style="TEXT-ALIGN: center">
                  <table class="main">
                        <tr>
                              <td>
                                    <center>
                                          
                                                <ItemTemplate>
                                                      <%# DataBinder.Eval(Container.DataItem, "FQDisplay") %>
                                                </ItemTemplate>
                                          </asp:DataList>
                                    </center>
                                    <br>
                              </td>
                        </tr>
                        <tbody>
                              
                              <tr align="center">
                                    <td colspan="2">
                                          <form id="Form1" method="post" runat="server">
                                                <asp:DataList id="DataList1" DataKeyField="FoodID" runat="server" OnItemDataBound="datalist_item_bind">
                                                      <ItemTemplate>
                                                      <tr><td colspan="7"><hr></td></tr>
                                                      <tr><td colspan="5">
                                                                              
                                                                              </td>
                                                                        <td width="10" rowspan="2">&nbsp;</td>
                                                                        <td rowspan="2">
                                                                        
                                                                        <asp:Calendar id="seldate" runat="server" BorderColor="purple" SelectedDate='<%# DataBinder.Eval(Container.DataItem, "mydate", "{0}") %>'></asp:Calendar>
                                                                        
                                                                  </td>
                                                                  </tr>
                                                            <tr align="center">
                                                                  <td align="left">
                                                                        <span style="display:none" id="Span1" runat="server">
                                                                              <%# DataBinder.Eval(Container.DataItem, "HMID") %>
                                                                        </span>
                                                                        <div class="formtextsm"><%# DataBinder.Eval(Container.DataItem, "NoNickDisplay") %>
                                                                              <%# DataBinder.Eval(Container.DataItem, "NickDisplay") %>
                                                                              &nbsp;</div>
                                                                        
                                                                  </td>
                                                                  <td width="5">&nbsp;</td>
                                                                  <td align="left">
                                                                        <span style="display:none" id="spanProdID" runat="server">
                                                                              <%# DataBinder.Eval(Container.DataItem, "FoodID") %>
                                                                        </span>
                                                                        <div class="formtextsmbld"><%# DataBinder.Eval(Container.DataItem, "FoodDesc") %>&nbsp;</div>
                                                                  
                                                                  </td>
                                                                  <td width="5">&nbsp;</td>
                                                                  <td>
                                                                        <asp:DropDownList ID="supplierDrop" DataTextField="HOft" DataValueField="FreqID" Runat="server"></asp:DropDownList>
                                                                        
                                                                  </td>
                                                                  
                                                            </tr>
                              </tbody>
                        </ItemTemplate> </asp:DataList>
                        <br>
                        <asp:Button id="cmdSubmit" runat="server" Text="Submit!" OnClick="cmdSubmit_Click"></asp:Button></FORM></TD></TR>
                  </table>
            </div>
      </body>
</HTML>
LVL 1
net_susanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

naveenkohliCommented:
Why are you executing the following lines twice on first load..

listFoods()
FQlist()

First they are getting called from PageLoad and then in PreRender.

PreRender is not under your control. This event is going to be fired by framework in series of steps it has to do to get the page rendered.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
net_susanAuthor Commented:
Once they change the dropdown value
<asp:DropDownList ID="supplierDrop" DataTextField="HOft" DataValueField="FreqID" Runat="server"></asp:DropDownList>

I need that entire row to go away. This PreRender code solved that perfectly for me on another page (where I wasn't using a calendar).
0
net_susanAuthor Commented:
If there was another way to make listfoods() execute again *after* the Submit code runs, that would be great too.

   Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim objconn As New SqlConnection("mystring")
        'asked from open to close
        objconn.Open()
        Dim objcmd As New SqlCommand("UpCh", objconn)
        objCmd.CommandType = CommandType.StoredProcedure
        objcmd.Parameters.Add("@FoodID", SqlDbType.Int)
        objcmd.Parameters.Add("@FreqID", SqlDbType.Int)
          For Each dlItem As DataListItem In DataList1.Items
            Dim txtProdName As TextBox = CType(dlItem.FindControl("txtprodname"), TextBox)
            Dim droplist As DropDownList = CType(dlItem.FindControl("supplierDrop"), DropDownList)
            Dim spanFoodID As HtmlGenericControl = CType(dlItem.FindControl("spanProdID"), HtmlGenericControl)
            objcmd.Parameters("@FoodID").Value = spanFoodID.InnerHtml
            objcmd.Parameters("@FreqID").Value = CInt(droplist.SelectedValue)
             objcmd.ExecuteNonQuery()            
        Next
        objconn.Close()
    End Sub
0
net_susanAuthor Commented:
I think this might be my solution:


Next
        objconn.Close()
        server.transfer("mypage.aspx")
        End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.