access controls inside formview inside loginview

Discussion in 'ASP .Net' started by wikkiwikkiwaa, Aug 3, 2006.

  1. hello,

    i am trying to access controls inside my formview1 nested inside
    loginview1. you cannot access the formview1 unless you are properly
    logged in.

    for loginview1, that seems to be fairly simple. a label control would
    be:
    Label label1 = (Label)loginview1.FindControl("nameoflabel");
    then i get to the data that was bound to that control.

    i cannot figure out how to get to the formview1 controls. the formview1
    defaults to the itemtemplate, but also has a edititem and iteminsert
    templates. the labels i am trying to get to inside formview1 are
    ZIPLabel, ADDR1Label, and CITYLabel. i cannot seem to get the syntax to
    get to them correct.

    i'm also not sure at what point they have been created and that i
    really have access to them. for example.

    i tried to get to them through one of the events formview1_DataBound,
    but they don't seem to exist yet.

    i'm missing something fundamental here and i'm starting to get
    frustrated. any help would be appreciated.

    thank you for your time
     
    wikkiwikkiwaa, Aug 3, 2006
    #1
    1. Advertising

  2. So long as the controls in the FormView are named uniquely within the
    formview, not just within the Template then it should be no problem, so just
    have to call two sets of FindControl

    e.g. to access a textbox that is within the formview:

    FormView MyFormView = (FormView)LoginView1.FindControl("FormViewID~");

    TextBox MyTextBox = (TextBox)MyFormView.FindControl("TextBoxID");

    MyTextBox.Text = "Some Words";

    However if you have a text box in the insert item template and the edit item
    template with the same ID then it will generate an error. Also if you try to
    retreive a control from the edit item template and the FormView is not in
    edit mode then you will probably get the object reference not set to instance
    of an object error.


    "wikkiwikkiwaa" wrote:

    > hello,
    >
    > i am trying to access controls inside my formview1 nested inside
    > loginview1. you cannot access the formview1 unless you are properly
    > logged in.
    >
    > for loginview1, that seems to be fairly simple. a label control would
    > be:
    > Label label1 = (Label)loginview1.FindControl("nameoflabel");
    > then i get to the data that was bound to that control.
    >
    > i cannot figure out how to get to the formview1 controls. the formview1
    > defaults to the itemtemplate, but also has a edititem and iteminsert
    > templates. the labels i am trying to get to inside formview1 are
    > ZIPLabel, ADDR1Label, and CITYLabel. i cannot seem to get the syntax to
    > get to them correct.
    >
    > i'm also not sure at what point they have been created and that i
    > really have access to them. for example.
    >
    > i tried to get to them through one of the events formview1_DataBound,
    > but they don't seem to exist yet.
    >
    > i'm missing something fundamental here and i'm starting to get
    > frustrated. any help would be appreciated.
    >
    > thank you for your time
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Aug 4, 2006
    #2
    1. Advertising

  3. thank you so much for your help. appreciate you taking the time to
    check out my problem.

    clickon wrote:
    > So long as the controls in the FormView are named uniquely within the
    > formview, not just within the Template then it should be no problem, so just
    > have to call two sets of FindControl
    >
    > e.g. to access a textbox that is within the formview:
    >
    > FormView MyFormView = (FormView)LoginView1.FindControl("FormViewID~");
    >
    > TextBox MyTextBox = (TextBox)MyFormView.FindControl("TextBoxID");
    >
    > MyTextBox.Text = "Some Words";
    >
    > However if you have a text box in the insert item template and the edit item
    > template with the same ID then it will generate an error. Also if you try to
    > retreive a control from the edit item template and the FormView is not in
    > edit mode then you will probably get the object reference not set to instance
    > of an object error.
    >
    >
    > "wikkiwikkiwaa" wrote:
    >
    > > hello,
    > >
    > > i am trying to access controls inside my formview1 nested inside
    > > loginview1. you cannot access the formview1 unless you are properly
    > > logged in.
    > >
    > > for loginview1, that seems to be fairly simple. a label control would
    > > be:
    > > Label label1 = (Label)loginview1.FindControl("nameoflabel");
    > > then i get to the data that was bound to that control.
    > >
    > > i cannot figure out how to get to the formview1 controls. the formview1
    > > defaults to the itemtemplate, but also has a edititem and iteminsert
    > > templates. the labels i am trying to get to inside formview1 are
    > > ZIPLabel, ADDR1Label, and CITYLabel. i cannot seem to get the syntax to
    > > get to them correct.
    > >
    > > i'm also not sure at what point they have been created and that i
    > > really have access to them. for example.
    > >
    > > i tried to get to them through one of the events formview1_DataBound,
    > > but they don't seem to exist yet.
    > >
    > > i'm missing something fundamental here and i'm starting to get
    > > frustrated. any help would be appreciated.
    > >
    > > thank you for your time
    > >
    > >
     
    wikkiwikkiwaa, Aug 9, 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. =?Utf-8?B?Q2FzZXk=?=

    inside the loginview

    =?Utf-8?B?Q2FzZXk=?=, Jan 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    472
    =?Utf-8?B?Q2FzZXk=?=
    Jan 13, 2006
  2. Jacob Donajkowski
    Replies:
    0
    Views:
    400
    Jacob Donajkowski
    Mar 8, 2007
  3. Andy B
    Replies:
    4
    Views:
    691
    Andy B
    Jan 16, 2008
  4. Jack
    Replies:
    1
    Views:
    946
    Alessandro Zifiglio
    Jul 3, 2006
  5. LLars
    Replies:
    2
    Views:
    285
    LLars
    Feb 14, 2006
Loading...

Share This Page