Strong Coders Community

Where the extreme coders hang out.

How to use findcontrol to find a control within an UpdatePanel during cross-page postback

Last post 06-04-2007 8:01 AM by anderdw2 . 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-24-2007 8:45 AM
    • anderdw2
    • Top 10 Contributor
    • Joined on 10-04-2006
    • Posts 13
    • Points 170

    How to use findcontrol to find a control within an UpdatePanel during cross-page postback

    Reply Contact

    Ok, hopefully someone can help

     I have a page, detail.aspx that is built on a masterpage.  The page contains an updatepanel (upTopNav) and panel (panel1)  that holds a textbox control (txt_vendor_ID) and a button.  The button click event has a postback URL of report.aspx.  I'm trying to find the control that is nested within the updatepanel, but I can't seem to get a value placed. I don't want to declare a page directive to use strongtype for the control, as I will have several pages doing a similar postback.

     I'm trying this

     If Not Page.PreviousPage Is Nothing Then
                Dim SourceTextBox As New TextBox
                SourceTextBox = CType(PreviousPage.FindControl("txt_vendor_ID"), TextBox)
                Vendor_ID = SourceTextBox.Text
    Else
                Vendor_ID = txt_vendor_ID.Text
    End If

     Any thoughts?

    Dave
    • Post Points: 20
  • 05-29-2007 7:53 AM In reply to
    • kampak1111
    • Top 50 Contributor
      Male
    • Joined on 02-07-2007
    • Poland
    • Posts 2
    • Points 25

    Re: How to use findcontrol to find a control within an UpdatePanel during cross-page postback

    Reply Contact

    Hi,

    This is a problem with FindControl. Text from help: "The FindControl method searches only the page's immediate, or top-level, container; it does not recursively search for controls in naming containers contained on the page"

    The solutions are:

    1. Use FindControlRecursive (you can find some code with google, or write yourself) instead of FindControl

    2. Through exact path to the control, for example (ContentPage with Panel with TextBox)

    string

    text = (( TextBox )PreviousPage.FindControl( "ctl00" ).FindControl( "form1" ).FindControl( "ContentPlaceHolder1" ).FindControl( "Panel1" ).FindControl( "TextBox1" )).Text;

    3. Through control.ClientID, for example

    text = ((

    TextBox )PreviousPage.FindControl( "ctl00$ContentPlaceHolder1$TextBox1" )).Text; or (depends of object naming)

    text = ((

    TextBox )PreviousPage.FindControl( "ctl00_ContentPlaceHolder1_TextBox1" )).Text;
    Kamil Pakur
    • Post Points: 20
  • 06-04-2007 8:01 AM In reply to
    • anderdw2
    • Top 10 Contributor
    • Joined on 10-04-2006
    • Posts 13
    • Points 170

    Re: How to use findcontrol to find a control within an UpdatePanel during cross-page postback

    Reply Contact

    Kampak,

     

    Thanks, that was very helpful. and solved the problem. I used the first example.

     

    Dave  

    Dave
    • Post Points: 5
Page 1 of 1 (3 items)

Copyright © 2006-2007 Strong Coders Community. All rights reserved. Privacy Statement | Terms Of Use
Advertise with us | Site Feedback | Chat and messenger powered by CuteSoft.NET

Powered by Community Server (Commercial Edition), by Telligent Systems