cant access the control...

Last post 08-21-2008 5:07 AM by Vince Xu - MSFT. 1 replies.

Sort Posts:

  • cant access the control...

    08-18-2008, 3:23 PM

    I have a formview which is inside the Ajax Tab.
    Inside formview i have a Textbox defined in the EditTemplate of formview.

    I have two issues:

     First i cant access tht control and second i need to pass this control as Update parameter which is not working either , since update cant find it either

     Here is the code:  ANY SOLUTIONS PLZ

    <cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">

    <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="General">

    <ContentTemplate>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

    <ContentTemplate>

    <asp:FormView ID="FormView1" runat="server" DataSourceID="T2SqlDataSource1" BackColor="LightGoldenrodYellow">

    ....

    <EditItemTemplate>

    <table id="EditTable" runat="Server">

    <tr>...

    <asp:TextBox ID="maxtruckcapacity" runat="server" Text='<%# Eval("MaxTruckCapacity") %>'></asp:TextBox>

    ....

    <UpdateParameters>

    <asp:SessionParameter Name="CustID" SessionField="Cust" />

    <asp:ControlParameter ControlID="ctl00$ContentPlaceHolder1$TabContainer1$TabPanel2$FormView1$maxtruckcapacity"  --doesnt work, also tried maxtruckcapacity and didnt work either..

    Name="maxtruckcapacity" PropertyName="text"  Type="Int32" />

    <%--<asp:Parameter Name="maxTruckcapacity" Type="Int32" /> --%>

    </UpdateParameters>

     

     

     

    http://saqdotnet.blogspot.com/
  • Re: cant access the control...

    08-21-2008, 5:07 AM
    Answer

    Hi,

    Firstly, please change the mode of FormView to "edit". Then you can use FindControl to retrieve the control.

    If it's hard to get it after changing to edit mode, you can use FindControlRecursive function to find specific control in the page.

    You can try the below code to get the directory of the control.

        Dim idcollection As String = ""
    
        Public Function FindControlRecursive(ByVal ctrl As Control, ByVal controlID As String) As Control
            If String.Compare(ctrl.ID, controlID, True) = 0 Then
    
                ' We found the control!
    
                Return ctrl
            Else
    
                ' Recurse through ctrl's Controls collections
    
                For Each child As Control In ctrl.Controls
                    Dim lookFor As Control = FindControlRecursive(child, controlID)
                    If lookFor IsNot Nothing Then
                        idcollection = idcollection & child.ID & "-"
    
                        Return lookFor ' We found the control
    
                    End If
    
                Next
    
                ' If we reach here, control was not found
    
                Return Nothing
    
            End If
        End Function
    
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim tb As Control = FindControlRecursive(Page, "TextBox12")
            If tb Is Nothing Then
                Response.Write("control not found" & "<br/>")
    
            Else
                Response.Write("control found" & "<br/>")
                Response.Write(idcollection)
            End If
    
    
        End Sub 

     The directory will be displayed so that you can use FindControl function to find it. Then you can also pass this control as Update parameter.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)