By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Apr 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Apr 11 '07 #2

P: n/a
On Apr 11, 4:08 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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

Apr 11 '07 #3

P: n/a
"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]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
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

Apr 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.