How to find which button was clicked in a repeater itemtemplate and find the value of textbox

Discussion in 'ASP .Net' started by AlecL, Apr 11, 2007.

  1. AlecL

    AlecL Guest

    Hi All,

    I am trying to capture the value of a textbox as a result of a button
    click event in a repeater, but it can't find the textbox.

    Here is what I am trying to do in the code for the click event:

    Dim prodkey As String = CType(FindControl("txtProductkey"),
    TextBox).Text.ToString()
    Response.Redirect("store_shoppingcart.aspx?pkey=" & prodkey)

    But it says that the textbox is not instantiated. Now I understand
    that I can get the row where that button is clicked but when I look
    for e.item that option is not available just the items collection is
    available.

    !!!!!!!!How do I find Out which button was clicked and how do I get
    the corresponding textbox value!!!!!!!!!!!!!!

    Please help!!!!

    Al
     
    AlecL, Apr 11, 2007
    #1
    1. Advertising

  2. RE: How to find which button was clicked in a repeater itemtemplate an

    The "sender" object parameter of the Click event handler will give you the
    button that was clicked, and you can look at it's ID property to find your
    way back to which row of the Repeater the clicked button is in.
    Then you can use that information to find the corresponding textbox.
    That is, assuming I read your intent correctly...
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "AlecL" wrote:

    > Hi All,
    >
    > I am trying to capture the value of a textbox as a result of a button
    > click event in a repeater, but it can't find the textbox.
    >
    > Here is what I am trying to do in the code for the click event:
    >
    > Dim prodkey As String = CType(FindControl("txtProductkey"),
    > TextBox).Text.ToString()
    > Response.Redirect("store_shoppingcart.aspx?pkey=" & prodkey)
    >
    > But it says that the textbox is not instantiated. Now I understand
    > that I can get the row where that button is clicked but when I look
    > for e.item that option is not available just the items collection is
    > available.
    >
    > !!!!!!!!How do I find Out which button was clicked and how do I get
    > the corresponding textbox value!!!!!!!!!!!!!!
    >
    > Please help!!!!
    >
    > Al
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 11, 2007
    #2
    1. Advertising

  3. AlecL

    AlecL Guest

    Re: How to find which button was clicked in a repeater itemtemplate an

    On Apr 11, 4:08 pm, Peter Bromberg [C# MVP]
    <> wrote:
    > The "sender" object parameter of the Click event handler will give you the
    > button that was clicked, and you can look at it's ID property to find your
    > way back to which row of the Repeater the clicked button is in.
    > Then you can use that information to find the corresponding textbox.
    > That is, assuming I read your intent correctly...
    > Peter
    >
    > --
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short urls & more: http://ittyurl.net
    >
    >
    >
    > "AlecL" wrote:
    > > Hi All,

    >
    > > I am trying to capture the value of a textbox as a result of a button
    > > click event in a repeater, but it can't find the textbox.

    >
    > > Here is what I am trying to do in the code for the click event:

    >
    > > Dim prodkey As String = CType(FindControl("txtProductkey"),
    > > TextBox).Text.ToString()
    > > Response.Redirect("store_shoppingcart.aspx?pkey=" & prodkey)

    >
    > > But it says that the textbox is not instantiated. Now I understand
    > > that I can get the row where that button is clicked but when I look
    > > for e.item that option is not available just the items collection is
    > > available.

    >
    > > !!!!!!!!How do I find Out which button was clicked and how do I get
    > > the corresponding textbox value!!!!!!!!!!!!!!

    >
    > > Please help!!!!

    >
    > > Al- Hide quoted text -

    >
    > - Show quoted text -


    Thanks, Peter!

    I looked at the sender object and it does not have an ID property.
    Will you have an example or is there another property that will give
    me this info?

    Any help would be appreciated.

    Al
     
    AlecL, Apr 11, 2007
    #3
  4. Re: How to find which button was clicked in a repeater itemtemplat

    "sender" is of type Object. You need to cast it to the type of the control
    that generated the entry of the Click hander, e.g.

    Button clickedButton = sender as Button;
    or
    Button clickedButton = (Button)sender;

    in VB.NET:

    Dim clickedButton as Button =CType(sender, Button)

    Cheers
    Peter


    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "AlecL" wrote:

    > On Apr 11, 4:08 pm, Peter Bromberg [C# MVP]
    > <> wrote:
    > > The "sender" object parameter of the Click event handler will give you the
    > > button that was clicked, and you can look at it's ID property to find your
    > > way back to which row of the Repeater the clicked button is in.
    > > Then you can use that information to find the corresponding textbox.
    > > That is, assuming I read your intent correctly...
    > > Peter
    > >
    > > --
    > > Site: http://www.eggheadcafe.com
    > > UnBlog: http://petesbloggerama.blogspot.com
    > > Short urls & more: http://ittyurl.net
    > >
    > >
    > >
    > > "AlecL" wrote:
    > > > Hi All,

    > >
    > > > I am trying to capture the value of a textbox as a result of a button
    > > > click event in a repeater, but it can't find the textbox.

    > >
    > > > Here is what I am trying to do in the code for the click event:

    > >
    > > > Dim prodkey As String = CType(FindControl("txtProductkey"),
    > > > TextBox).Text.ToString()
    > > > Response.Redirect("store_shoppingcart.aspx?pkey=" & prodkey)

    > >
    > > > But it says that the textbox is not instantiated. Now I understand
    > > > that I can get the row where that button is clicked but when I look
    > > > for e.item that option is not available just the items collection is
    > > > available.

    > >
    > > > !!!!!!!!How do I find Out which button was clicked and how do I get
    > > > the corresponding textbox value!!!!!!!!!!!!!!

    > >
    > > > Please help!!!!

    > >
    > > > Al- Hide quoted text -

    > >
    > > - Show quoted text -

    >
    > Thanks, Peter!
    >
    > I looked at the sender object and it does not have an ID property.
    > Will you have an example or is there another property that will give
    > me this info?
    >
    > Any help would be appreciated.
    >
    > Al
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Apr 11, 2007
    #4
    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. Bennett Haselton
    Replies:
    1
    Views:
    5,341
    Joe Fallon
    Sep 24, 2004
  2. Andy B
    Replies:
    1
    Views:
    993
    bruce barker
    Nov 15, 2008
  3. bthumber
    Replies:
    4
    Views:
    478
    bthumber
    Jun 25, 2010
  4. Yossi

    Which button was clicked and on which row?

    Yossi, Nov 17, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    738
    Yossi
    Nov 17, 2006
  5. Jim Mitchell
    Replies:
    0
    Views:
    204
    Jim Mitchell
    Jul 12, 2003
Loading...

Share This Page