473,385 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
3 10460
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MattB | last post by:
I'm trying to build a repeater to generate text boxes based on a value in a table. The number of boxes will vary so the repeater seemed like the logical choice. I want to make the id property of...
4
by: huzz | last post by:
I am trying to access a DropDownList control inside a repeater using ItemCommand as shown below but for some reason i can't access the DropDownList. When i step through the debug i get <undefine...
10
by: william | last post by:
Hi, I have a datagrid, inside there is a templete item, it's button. I want to do some thing when user click the button, but do not want the postback event happens. How can I do it? Thanks. ...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
1
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small,...
0
by: datakix | last post by:
After 16 hours of frustration, I've managed to solve this problem for a project I'm working on. The 'trick' is set EnableViewState="False" for the asp:textbox inside the Repeater control. The...
3
by: Shimon Sim | last post by:
I put linkbutton in a repeater header. I attached event handler in makeup as onclick="btnSort_Click". Made btnSort_Click method public. It doesn't fire if I click on it. I tried to attach it in...
4
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button...
0
by: maffarazo | last post by:
Hi! Im currenty using a repeater to loop out all my data in my database and everything is working just great =) I just have a small problem. how do I get wich id the item is from the database?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.