?
Solved

Page_PreRender Firing after ASP Calendar Click

Posted on 2006-04-21
4
Medium Priority
?
571 Views
Last Modified: 2007-12-19
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>
0
Comment
Question by:net_susan
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 2000 total points
ID: 16509293
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
 
LVL 1

Author Comment

by:net_susan
ID: 16509319
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
 
LVL 1

Author Comment

by:net_susan
ID: 16509701
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
 
LVL 1

Author Comment

by:net_susan
ID: 16511789
I think this might be my solution:


Next
        objconn.Close()
        server.transfer("mypage.aspx")
        End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

809 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