Something I need to get straight! (server and client side)

Greg.NET

Active member
Joined
Jun 4, 2007
Messages
27
Programming Experience
1-3
today I was trying to populate a dropdownlist in the page's load function in the code behind page. I set the "selectedvalue" property to a field from the datasource of the formview that the dropdownlist was in.

but I kept getting a page error saying that the selected value did not exist in the list.

So I finally realised that the page was trying to set the selectedvalue before the items were inserted into the dropdownlist.

Can anyone explain the order of execution in asp for me? I just assumed the page load would be the first thing to execute.
 
to clarify a bit, I was setting the selectedvalue property in the markup, but I was populating the list in the code behind page. And this resulted in the page trying to select a value before the list was even populated.
 
Page execution sequence

1. PreInt
2. Init
3. InitComplete
4. PreLoad
5. Load
6. LoadComplete
7. PreRender
8. PreRenderComplete
9. SaveStateComplete
10. Unload

the page load event happens before any control events and preRender hanppens after any control events

to access a control in a FormViewControl

dim ddl as DropDownList = ctype(FormViewControl.FindControl("DropDownListControlName"),DropDownList)
 
thanks hadinatayp. But I just cant get this to work. It tries to select a value before the items are bound to it. heres the code

VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.RegisterStartupScript("displaypanel80", "<script language='javascript'>panelHideShowSections('inline','none','none');</script>")

        'Dim cre As DropDownList = Me.GridView1.FindControl("")
        ' cre.datasou()
        'populateDropDownBoxes()
        populateDropDownBoxes()

    End Sub




and heres the markup:

HTML:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="false"
            AutoGenerateColumns="False" DataKeyNames="Project_Number" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="Project_Nam" HeaderText="Project_Nam" SortExpression="Project_Nam" />
                    <asp:BoundField DataField="Project_Number" HeaderText="Project_Number" InsertVisible="False"
                        ReadOnly="True" SortExpression="Project_Number" />
                    <asp:BoundField DataField="CRE_TOP5" HeaderText="CRE_TOP5" SortExpression="CRE_TOP5" >                      
                    </asp:boundfield>
                    <asp:BoundField DataField="Site" HeaderText="Site" SortExpression="Site" />
                    <asp:BoundField DataField="ProjectDescription" HeaderText="ProjectDescription" SortExpression="ProjectDescription" />
                    <asp:BoundField DataField="Dept_Name" HeaderText="Dept_Name" ReadOnly="True" SortExpression="Dept_Name" />
                    <asp:TemplateField HeaderText="CRE Top5">
                        <ItemTemplate>
                        <asp:DropDownList id="DropDownList23"  AppendDataBoundItems="true"    runat="server" Width="158px" >
                        </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>                                
                </Columns>  
            </asp:GridView>
 
Last edited by a moderator:
Back
Top