accesing controls in code-behind

Discussion in 'ASP .Net' started by R.A.M., Dec 20, 2006.

  1. R.A.M.

    R.A.M. Guest

    Hello,
    I am learning ASP.NET.
    On .aspx page I have a data-list with text-box that I would like to read
    during line modification.

    <asp:DataList ...
    OnEditCommand="Sample_Edit" >
    ...
    <EditItemTemplate>
    ...
    <asp:TextBox ID="SampleEdit" runat="server" />
    ...
    </EditItemTemplate>
    ...
    </asp:DataList>

    In code-behind I have:

    protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    {
    ...
    string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text;
    // here problem
    ...
    }

    The problem is that although e.Item is fine, FindControl returns null.
    Could you help me to programme it correctly?
    Thank you !!!
    /RAM/
     
    R.A.M., Dec 20, 2006
    #1
    1. Advertising

  2. R.A.M.

    R.A.M. Guest

    I have also tried this way:
    Sample =
    ((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;

    and this way:
    Sample =
    ((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;

    but it doesn't work, either.

    U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    news:emav46$aas$...
    > Hello,
    > I am learning ASP.NET.
    > On .aspx page I have a data-list with text-box that I would like to read
    > during line modification.
    >
    > <asp:DataList ...
    > OnEditCommand="Sample_Edit" >
    > ...
    > <EditItemTemplate>
    > ...
    > <asp:TextBox ID="SampleEdit" runat="server" />
    > ...
    > </EditItemTemplate>
    > ...
    > </asp:DataList>
    >
    > In code-behind I have:
    >
    > protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    > {
    > ...
    > string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text;
    > // here problem
    > ...
    > }
    >
    > The problem is that although e.Item is fine, FindControl returns null.
    > Could you help me to programme it correctly?
    > Thank you !!!
    > /RAM/
    >
    >
     
    R.A.M., Dec 20, 2006
    #2
    1. Advertising

  3. R.A.M.

    R.A.M. Guest

    OK, I solved. SampleEdit is not accessible before edit mode set.

    U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    news:embpqv$2fq$...
    >I have also tried this way:
    > Sample =
    > ((TextBox)SampleDataList.Items[e.Item.ItemIndex].FindControl("SampleEdit")).Text;
    >
    > and this way:
    > Sample =
    > ((TextBox)SampleDataList.SelectedItem.FindControl("SampleEdit")).Text;
    >
    > but it doesn't work, either.
    >
    > U¿ytkownik "R.A.M." <> napisa³ w wiadomo¶ci
    > news:emav46$aas$...
    >> Hello,
    >> I am learning ASP.NET.
    >> On .aspx page I have a data-list with text-box that I would like to read
    >> during line modification.
    >>
    >> <asp:DataList ...
    >> OnEditCommand="Sample_Edit" >
    >> ...
    >> <EditItemTemplate>
    >> ...
    >> <asp:TextBox ID="SampleEdit" runat="server" />
    >> ...
    >> </EditItemTemplate>
    >> ...
    >> </asp:DataList>
    >>
    >> In code-behind I have:
    >>
    >> protected void Sample_Edit(object sender, DataListCommandEventArgs e)
    >> {
    >> ...
    >> string Sample = ((TextBox)e.Item.FindControl("SampleEdit")).Text;
    >> // here problem
    >> ...
    >> }
    >>
    >> The problem is that although e.Item is fine, FindControl returns null.
    >> Could you help me to programme it correctly?
    >> Thank you !!!
    >> /RAM/
    >>
    >>

    >
    >
     
    R.A.M., Dec 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    631
    Alphonse Giambrone
    Jun 28, 2003
  2. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    522
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  3. ozgur develioglu

    Accesing embedded controls??

    ozgur develioglu, Jul 21, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    136
    ozgur develioglu
    Jul 21, 2003
  4. ozgur develioglu

    Accesing embedded controls

    ozgur develioglu, Jul 21, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    140
    ozgur develioglu
    Jul 21, 2003
  5. ozgur develioglu

    Accesing embedded controls

    ozgur develioglu, Jul 21, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    119
    ozgur develioglu
    Jul 21, 2003
Loading...

Share This Page