findcontrol on textbox returns empty string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rimu Atkinson

    #1

    findcontrol on textbox returns empty string

    hi all

    i use FindControl to get a textbox, and i get a textbox object, but it's
    ..Text property is empty.

    some background info: i have a DataList, which has a template column in it,
    and in that template column i define a textbox.

    <asp:TemplateCo lumn HeaderText="Qua ntity">
    <ItemTemplate >
    <asp:TextBox id="Quantity" runat="server" Columns="4" MaxLength="3"
    Text='<%# DataBinder.Eval (Container.Data Item, "Quantity") %>' width="40px"
    />
    </ItemTemplate>
    </asp:TemplateCol umn>

    Later on, i want to go through all the rows in the datalist (called MyList),
    and do some processing based on the contents of the textboxes, which may
    have been changed by the user.

    For i = 0 To MyList.Items.Co unt - 1

    Dim quantityTxt As TextBox = CType(MyList.It ems(i).FindCont rol("Quantity") ,
    TextBox)

    'do some stuff here

    Next

    quantityTxt.Tex t is always vbNullstring. i have tried
    MyList.Items(i) .Cells(2).FindC ontrol("Quantit y") as well, which makes no
    difference.

    any idea why??

    any help very much appreciated.

    thanks

    Rimu



  • asneader

    #2
    Re: findcontrol on textbox returns empty string

    I had a similar problem when creating controls dynmically on a page.
    Make sure that the call that creates the datalist is not in a "If Not
    IsPostBack Then" statement. The "dynamic" controls have to be
    recreated when the page is submitted to get values from them. I hope
    this helps.

    "Rimu Atkinson" <rimu1@paradise .net.removenosp amthing.nz> wrote in message news:<UsETb.203 76$ws.2719954@n ews02.tsnz.net> ...[color=blue]
    > hi all
    >
    > i use FindControl to get a textbox, and i get a textbox object, but it's
    > .Text property is empty.
    >
    > some background info: i have a DataList, which has a template column in it,
    > and in that template column i define a textbox.
    >
    > <asp:TemplateCo lumn HeaderText="Qua ntity">
    > <ItemTemplate >
    > <asp:TextBox id="Quantity" runat="server" Columns="4" MaxLength="3"
    > Text='<%# DataBinder.Eval (Container.Data Item, "Quantity") %>' width="40px"
    > />
    > </ItemTemplate>
    > </asp:TemplateCol umn>
    >
    > Later on, i want to go through all the rows in the datalist (called MyList),
    > and do some processing based on the contents of the textboxes, which may
    > have been changed by the user.
    >
    > For i = 0 To MyList.Items.Co unt - 1
    >
    > Dim quantityTxt As TextBox = CType(MyList.It ems(i).FindCont rol("Quantity") ,
    > TextBox)
    >
    > 'do some stuff here
    >
    > Next
    >
    > quantityTxt.Tex t is always vbNullstring. i have tried
    > MyList.Items(i) .Cells(2).FindC ontrol("Quantit y") as well, which makes no
    > difference.
    >
    > any idea why??
    >
    > any help very much appreciated.
    >
    > thanks
    >
    > Rimu[/color]

    Comment

    Working...