473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(FindContr ol("txtProductk ey"),
TextBox).Text.T oString()
Response.Redire ct("store_shopp ingcart.aspx?pk ey=" & 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 10492
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(FindContr ol("txtProductk ey"),
TextBox).Text.T oString()
Response.Redire ct("store_shopp ingcart.aspx?pk ey=" & 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...@yaho o.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(FindContr ol("txtProductk ey"),
TextBox).Text.T oString()
Response.Redire ct("store_shopp ingcart.aspx?pk ey=" & 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...@yaho o.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(FindContr ol("txtProductk ey"),
TextBox).Text.T oString()
Response.Redire ct("store_shopp ingcart.aspx?pk ey=" & 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
263
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 each text box correspond to a value in the datatable. I have the following which does not work (compile errors). Can anyone tell me if this can be done, and if so what am I doing wrong? <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate>...
4
34529
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 value> for the DropDownList What am i doing wrong? <asp:Repeater ID="Repeater1" Runat="server" OnItemDataBound="create_ddl" OnItemCommand="Repeater1_ItemCommand"> <HeaderTemplate>
10
3666
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. william
25
4072
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
1
2294
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, medium, large), a price, a checkbox to say whether or not the variation is on special offer and a special price. I can pull the values out of the database OK and display them in a repeater. What I want to do is have a set of controls below the...
0
10548
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 problem is that by default the asp:textbox ViewState is True. This means that the textbox value is automatically preserved between postback (saved in the __VIEWSTATE hidden field and restored during a page postback).
3
4166
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 ItemDataBound event but I think it is too late. What am I doing wrong? Thanks Shimon.
4
3732
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 both inside and outside of the updatepanel and the event doesn't get called either way. What might I be missing here? Incidently, something else, kind of weird, is happening when the button is clicked, a required field validator control in a...
0
2283
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? I cant put it in to a label,literal or something like that. When I searched about it I found out that I should use something like <asp:placeholder /> but I dont know how to get it to work Here's my code so far aspx:
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10153
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8830
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5272
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2800
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.