How to get a control... asp (c#)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flyingAway@gmx.net

    How to get a control... asp (c#)

    Hi,

    in a for-next loop i create some ImageButtons in runtime.
    How to get the controls after I clicked one of these Buttons?
    I tried it with
    ctrlCurrImgBtn =
    (ImageButton)Co nvert.ChangeTyp e(FindControl(C urrID),typeof(I mageButton));
    but I get a System.NullRefe renceException.
    I tried to create the Controls once more but I get an Exeption because
    there are more than one Control with the same ID.

    Some Ideas?

    Thank's

  • Scott Allen

    #2
    Re: How to get a control... asp (c#)

    All of the controls need a unique ID. Perhaps you can double check the
    ID you are searching for with FindControl to the control ID you see
    when you do a View Source on the page in IE.

    --
    Scott


    On Wed, 14 Jul 2004 19:20:50 GMT, flyingAway@gmx. net wrote:
    [color=blue]
    >Hi,
    >
    > in a for-next loop i create some ImageButtons in runtime.
    >How to get the controls after I clicked one of these Buttons?
    >I tried it with
    >ctrlCurrImgB tn =
    >(ImageButton)C onvert.ChangeTy pe(FindControl( CurrID),typeof( ImageButton));
    >but I get a System.NullRefe renceException.
    >I tried to create the Controls once more but I get an Exeption because
    >there are more than one Control with the same ID.
    >
    >Some Ideas?
    >
    >Thank's[/color]

    Comment

    • flyingAway@gmx.net

      #3
      Re: How to get a control... asp (c#)

      I know the IDs, because I created it. (ImgBtn_1_1, ImgBtn_1_2,...
      ImgBtn_2_1,ImgB tn_2_2,... )
      But after I clicked on one of these Buttons
      FindControl(Img Btn_1_1),typeof (ImageButton) is null.
      When i try to create a ImageButton with ID ImgBtn_1_1 there is a
      Exeption because it's not unique. So my question is? ImgBtn_1_1 exists
      but how can i get it. ctrlCurrImgBtn =
      (ImageButton)Co nvert.ChangeTyp e(FindControl(I mgBtn_1_1),type of(ImageButton) );
      doesn,t work. There has to be another commande.


      Scott Allen schrieb:[color=blue]
      > All of the controls need a unique ID. Perhaps you can double check the
      > ID you are searching for with FindControl to the control ID you see
      > when you do a View Source on the page in IE.
      >
      > --
      > Scott
      > http://www.OdeToCode.com
      >
      > On Wed, 14 Jul 2004 19:20:50 GMT, flyingAway@gmx. net wrote:
      >
      >[color=green]
      >>Hi,
      >>
      >> in a for-next loop i create some ImageButtons in runtime.
      >>How to get the controls after I clicked one of these Buttons?
      >>I tried it with
      >>ctrlCurrImgBt n =
      >>(ImageButton) Convert.ChangeT ype(FindControl (CurrID),typeof (ImageButton));
      >>but I get a System.NullRefe renceException.
      >>I tried to create the Controls once more but I get an Exeption because
      >>there are more than one Control with the same ID.
      >>
      >>Some Ideas?
      >>
      >>Thank's[/color]
      >
      >[/color]

      Comment

      • Scott Allen

        #4
        Re: How to get a control... asp (c#)

        The control IDs are not necessarily what you specify. The runtime can
        add a prefix if you are inside of certain containers. If you have the
        image buttons inside one of these containers, that would explain why
        calling FindControl at the page level doesn't find the control.
        See http://odetocode.com/Articles/116.aspx

        --s

        On Thu, 15 Jul 2004 04:04:24 GMT, flyingAway@gmx. net wrote:
        [color=blue]
        >I know the IDs, because I created it. (ImgBtn_1_1, ImgBtn_1_2,...
        >ImgBtn_2_1,Img Btn_2_2,... )
        >But after I clicked on one of these Buttons
        >FindControl(Im gBtn_1_1),typeo f(ImageButton) is null.
        >When i try to create a ImageButton with ID ImgBtn_1_1 there is a
        >Exeption because it's not unique. So my question is? ImgBtn_1_1 exists
        >but how can i get it. ctrlCurrImgBtn =
        >(ImageButton)C onvert.ChangeTy pe(FindControl( ImgBtn_1_1),typ eof(ImageButton ));
        >doesn,t work. There has to be another commande.
        >
        >
        >Scott Allen schrieb:[color=green]
        >> All of the controls need a unique ID. Perhaps you can double check the
        >> ID you are searching for with FindControl to the control ID you see
        >> when you do a View Source on the page in IE.
        >>
        >> --
        >> Scott
        >> http://www.OdeToCode.com
        >>
        >> On Wed, 14 Jul 2004 19:20:50 GMT, flyingAway@gmx. net wrote:
        >>
        >>[color=darkred]
        >>>Hi,
        >>>
        >>> in a for-next loop i create some ImageButtons in runtime.
        >>>How to get the controls after I clicked one of these Buttons?
        >>>I tried it with
        >>>ctrlCurrImgB tn =
        >>>(ImageButton )Convert.Change Type(FindContro l(CurrID),typeo f(ImageButton)) ;
        >>>but I get a System.NullRefe renceException.
        >>>I tried to create the Controls once more but I get an Exeption because
        >>>there are more than one Control with the same ID.
        >>>
        >>>Some Ideas?
        >>>
        >>>Thank's[/color]
        >>
        >>[/color][/color]

        --
        Scott

        Comment

        Working...