Problem with getting the value from a textbox

Hi

I have a shopingcart with a gridview containing the products in the shopingcart, a textbox for changing the quantity and a button for submitting the change.

The textbox first holds the current number of a product, but the user should be able to change this.

How do i get hold of the value in the textbox?

Here's some code:

The gridview (or relevant parts of it):

 

 	<ItemTemplate>
                 <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Antal") %>' Width="20px"></asp:TextBox>
                </ItemTemplate>
 

 

<ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Uppdatera" CommandArgument='<%# Eval("ProdId") %>' OnCommand="Button1_Click" />
                </ItemTemplate>

 And the code for the update:

Sub Button1_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim ProdId = e.CommandArgument.ToString
        Dim SessId = Session.SessionID
        Dim NewAntal = TextBox3.ToString 'This gives an error TextBox3 not declared
 Thanks!
0
Jonas_G
9/14/2007 11:38:50 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

10 Replies
895 Views

Similar Articles

[PageSpeed] 51

Hi Jonas_G,

Jonas_G:

        Dim NewAntal = TextBox3.ToString 'This gives an error TextBox3 not declared

 

That's pretty normal, because .NET searches only the present control container and in your case the TextBox3 is in the GridView container. I don't now the code in VB, but try using FindControl() to find and access the textbox inside the GridView.

 


Servus,
Klaus

I haven't the faintest idea, but great many therefrom.
klaus_b@.NET
0
klaus_b
9/14/2007 12:15:35 PM

 Hi ...

           Iam not understanding why u r converting the whole textbox to string

I think this is the error change it to
 

Dim NewAntal = TextBox3.Text.ToString 
I just see it in one go not in deep if problem is not resolved coma again will surely be replied 
 
 

 

 

 

 


Nothing is impossible as the IMPOSSIBLE word itself says I M Possible...just you have to try..u get all what you desire

Pradeep Bisht
BLOG ::--> http://dotnetarmy.blogspot.com/
URL ::--> http://www.asp.net
0
Spanco
9/14/2007 12:15:47 PM

klaus_b:

Hi Jonas_G,

Jonas_G:

        Dim NewAntal = TextBox3.ToString 'This gives an error TextBox3 not declared

 

That's pretty normal, because .NET searches only the present control container and in your case the TextBox3 is in the GridView container. I don't now the code in VB, but try using FindControl() to find and access the textbox inside the GridView.

 

Thanks!

How should it look in C#?

 i know a little C , and an example would help me along the way.

0
Jonas_G
9/14/2007 12:41:38 PM

TextBox3 is inside GridView Item Template.. so you need to find the control and get the value... here i am not having exact scenario that you want

but to get all the values of TextBox3 in all rows of the GridView... you can as...

C# 

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            //....here in Rows[i].Cells[1] means i assume that TextBox3 is in your second column..
            //....so make the cells index accodringly...
            Response.Write(((TextBox)GridView1.Rows[i].Cells[1].FindControl("TextBox1")).Text.Trim());
        }

 

VB 

 

        For i As Integer = 0 To GridView1.Rows.Count - 1
            '....here in Rows[i].Cells[1] means i assume that TextBox3 is in your second column..
            '....so make the cells index accodringly...
            Response.Write((CType(GridView1.Rows(i).Cells(1).FindControl("TextBox1"), TextBox)).Text.Trim())
        Next i

hope it helps./. 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
9/14/2007 12:55:13 PM

kaushalparik27:

VB 

 

        For i As Integer = 0 To GridView1.Rows.Count - 1
            '....here in Rows[i].Cells[1] means i assume that TextBox3 is in your second column..
            '....so make the cells index accodringly...
            Response.Write((CType(GridView1.Rows(i).Cells(1).FindControl("TextBox1"), TextBox)).Text.Trim())
        Next i

hope it helps./. 

That helped me alot, thanks!

I put Rows(0) and it returned the textbox3 value from the first row, so far so good...

but how do i get it to pick out the value for the row i want to change by clicking the button in that row?

i.e

i have 4 items in my shopingcart (i.e 4 rows in the gridview) and i want to add 3 pieces of item 1 (row(0)).

Then i want to add 5 pieces of item 4 (row(3)). All this is done by hitting the update button on the row i want to change.

0
Jonas_G
9/14/2007 1:31:27 PM

Jonas_G:
i want to change by clicking the button in that row?
 

so you must be having button's click event...

in that event you can change value for that perticular row as...

sub Button1_click(byval sender as object,byval e as eventargs)

dim gvr as new GridViewRow

gvr = Ctype(Ctype(sender,Button).Perent.Parent,GridViewRow)

'...now get the TextBox3 value from gvr as... gvr is the current Row of which Update Button is clicked... 

end sub

 

hope it helps./. 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
9/14/2007 1:38:23 PM

Isn't there something like this (not exactly this, already tried that)

 

Dim NewAntal = GridView1.SelectedRow.FindControl("TextBox3").ToString
        Response.Write(NewAntal)
  a simple way to get hold of the textbox for a specific row?
0
Jonas_G
9/14/2007 4:06:46 PM

Jonas_G:

Isn't there something like this (not exactly this, already tried that)

 

Dim NewAntal = GridView1.SelectedRow.FindControl("TextBox3").ToString
        Response.Write(NewAntal)

  a simple way to get hold of the textbox for a specific row?

 

yes of course,  but only when you are selecting any perticular row (just like we do with SelectCommand Field) when you click the update button, then only you can get the SelectedRow to some row value otherwise it returns -1.

so here, i assume that any row is not get selected...

 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
9/15/2007 4:04:44 AM

 

        For i As Integer = 0 To GridView1.Rows.Count - 1
            '....here in Rows[i].Cells[1] means i assume that TextBox3 is in your second column..
            '....so make the cells index accodringly...
            Response.Write((CType(GridView1.Rows(i).Cells(1).FindControl("TextBox1"), TextBox)).Text.Trim())
        Next i

hope it helps./. 

If we back up a little and use this approach how do i get hold of the prodId for each row.

The prodId is a boundfield like this:

<asp:BoundField DataField="ProdId" />
 
0
Jonas_G
9/15/2007 8:50:46 AM

Fixed it!

 

Dim Prodid = GridView1.Rows(i).Cells(0).Text
 
0
Jonas_G
9/15/2007 11:09:06 AM
Reply:

Similar Artilces:

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

problem with get value from textbox after get it value in load page
hi every one  i have problem with my web site when i get textbox value in load page   and Changed textbox the page do not take last value .   it take value in load page   this is code:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)   TextBox1.Text = "aa" End SubProtected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox(TextBox1.Text) End Sub   when i press button message write "aa" while i changed the textbox   please if enyone knowen help me &nbs...

Problem getting an input value from a textbox in a GridView control
I placed a text box in one of my template columns in a gridview control:<Columns>                <asp:CommandField ShowEditButton="True" />                <asp:TemplateField><ItemTemplate><asp:TextBox runat=server ID="TextBox" Width="30"></asp:TextBox></ItemTemplate></asp:TemplateField> </Columns>Upon opening a page, my gridview is set up to be populate...

Problem getting input value from a textbox in a Gridview Control
I placed a text box in one of my template columns in a gridview control:<Columns>                <asp:CommandField ShowEditButton="True" />                <asp:TemplateField><ItemTemplate><asp:TextBox runat=server ID="TextBox" Width="30"></asp:TextBox></ItemTemplate></asp:TemplateField> </Columns>Upon opening a page, my gridview is set up to be populate...

Getting value from a textbox control that was filled with a value from javascript
 I have a textbox control (seen below txtMileageDollars1) that gets filled with javascript based on the number of miles a user types into another textbox (txtMileageMiles1) control.  When I post back with the submit button, the value is blank.  I've tried setting EnableViewState to false, but still cannot get a value on postback.  Does anyone have a solution?   Miles<asp:TextBox ID="txtMileageMiles1" runat="server" Width="50px"></asp:TextBox>   Total (txtMileageMiles1 * rate with javascript)<asp:TextBox...

How to get the Value from the Textbox ?Textbox is created by using add control function.
  Dim textWG As New HtmlInputText textWG.text="Wage Rate" textWG.ID = "txtWG" me.control.add(textWG) i write this code at form load.moreover this form have one save button to save the value from the "txtWG" to database this textbox will be appear when form finish load.but after click save button the value cant be save into database. tat textbox become empty when user click the save button. how can i get the value from that textbox ? Please advice me.Thank you You are using a HTML control and by default, HTML controls dont have a mechanism to pres...

problem with getting textbox value
when i pressed button add, the following code would add a text box to datagridTextBox txtEdit = new TextBox();dgTest.Items[0].Cells[0].Controls.Add( txtEdit ); After that i pressed button delete, the following would remove the textbox from datagridTextBox txtEdit = ( TextBox ) dgTest.Items[0].Cells[0].FindControl("txtEdit");// lblTest.Text = txtEdit.TextdgTest.Items[0].Cells[0].Controls.Remove( txtEdit );What i can not understand is that it removed the textbox sucessfully that means it could find the textbox but it can't not get the text that i typed in the textboxThanks TextBox txt...

problem getting textbox values dynamically
Ok I am trying to loop through a table (tbltest) get all of my textboxes. and assign there .text to a database. Here just to simplify I have been trying to just assign it to a label. here is the code. Dim c As Control For Each c In tbltest.Controls lbltest.Text = c.text Next Problem is it won't let me use .text. anyone know a way around this one. Or am I doing something else wrong? Something like this is probably what you are after: Dim c As Control For Each c In tbltest.Controls 'Is the type of c a TextBox ...

problem in getting edited value of a textbox
hi, I have a textbox inside a usercontrol registration.ascx. <asp:TextBox ID="email" runat="server" Width="260px"></asp:TextBox> when the user wants to edit his account then this textbox is populated with the email address that the user is using currently. the problem is that when the user edits the textbox then I am unable to get the edited value. Say the old email id is demo@abc.com and the user changed it to demo123@abc.com then when i am doing String sEmail = email.Text i am getting demo@abc.com instead of  demo123@abc.com. here i...

Problem Getting User Control Value
Need some help with a test script.  I'm attempting to display the value of ucLabel (a user control label) on my parent page named userpage.aspx.  Userpage.aspx is able to find the control named ucLabel but I can't get the value to write to the label on my aspx page (upLabel).  Any suggestions?  The user control and user page code-behind is below. Code-behind for ascx User Control Named usercontrol: namespace AIGACO{ using System; using System.Web.UI; using System.Web.UI.WebControls;  public class usercontrol : UserControl {  prote...

Problem getting TextBox Value in DataList.
hai guyz, i'm having a problem getting value from TextBox in the DataList Control. My situation is, i got one "Add to Cart" button,when user press the button it will trigger the Code below (catalog.aspx.cs ).It found the textbox control but can't get the value that i entered.Any idea guyz?.catalog.aspx<form id="Form1" method="post" runat="server"> <asp:datalist id="DataList1" runat="server" GridLines="Horizontal" RepeatColumns="1" OnUpdateCommand="DataList1_Update"> <ItemTemplate> <asp:LinkButton CommandName="Update" Runat="server" ID="lnkAdd...

problem in getting edited value from a textbox
hi, when a user clicks on edit profile link i am showing the ´new registration form with the user's data filled in. The problem is that when the user edits his data and clicks on the save button i am not getting the new edited data. Instead of giving me the new data textbox.Text is giving the same old value that I am displaying. what I need to do to get the new value? <asp:TextBox ID="email" runat="server" Width="260px"></asp:TextBox> sEmail = email.Text;     tamanna06:when a user clicks on edit profile link i am showing the ...

Problem getting focus in textbox
I am using a CreateUserWizard.  For some reason, I am unable to get focus into my textboxes on mouse click.   On my page_load, I have added some code to get the focus on the first textbox (FirstName.Focus()) and the user can tab through the rest of the fields. However, I need the user to be able to click on the textboxes and gain focus that way. Here's some code from the beginning of the first step.  As noted, I cannot click on any of the textboxes to gain focus.  The only way this works with mouse clicks is if I click on the associated text label next to the te...

problem while getting values from dynamically created textboxes
 Hi FriendsI have created some text boxes dynamically and I have problem while accessing their changed values. And I am using the following code. 1 TextBox t =(TextBox) this.form1.FindControl("field1"); 2 string name = t.Text;   When I try to execute the second line i.e. getting values from the text box, it results with Object reference not set to an instance of object. field1, fiedl2.... all are valid text box ids and they are present in the page.how to solve this? If you are using master page then field1 is changed to other name. Generally for objec...

How to get the value of a dynamically created textbox control
Hi,  Can anyone tell me how to get the entered value from a dynamically created textbox apart from getting it from the TextChanged eventhandler? Regards, Vidya Friend, check this thread as similar scenario is discussed over http://forums.asp.net/t/1051661.aspx http://forums.asp.net/t/939377.aspx Another one Good luck!Please Don't forget to click "Mark as Answer" on the post that helped you.This can be beneficial to other community members reading the thread.  use Request["TextBoxId"] to get the value entered in it....Also white creating it rememb...

Problem entering URL value into textbox control
I have a textbox server control on a webform.  Whenever the user enters a URL that contains ".asp" or ".jsp", the browser returns a "Page cannot be displayed (Cannot find server or DNS Error)" in IE.   I cannot duplicate this problem on my dev machine (works fine), thus I cannot debug it.  I have validatePage=False on the page that collects this data.  Any help would be appreciated. Give you a blog about how to solve "Page cannot be displayed (Cannot find server or DNS Error)" in IE for reference.http://www.duxcw.com/yab...

Radiobuttonlist control problem, cant get the value
HelloI have a page where i have a radiobuttonlist that gets its values from a access database. I looks ok, but when i try to set session values or the text in a label with it, nothing happens.I have tryed to set the contol to autopostback, and also tryed to set  "If Page.IsValid Then" before but nothing helps. Any tip? Im a newbie in programming as you maybe understand :-)My code from the .vb filePrivate Sub rblOmrade_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rblOmrade.SelectedIndexChanged Session("omrade_ID") = Me.rblOmrade.SelectedValu...

Problem with getting the value of a dynamically created CONTROL
Dear,I'm facing a problem with dynamically created controlsI'm creating RadioButtons  according to certain data from a database, the problem is that the RadioButtons are being created and are being displayed in a dynamically created HtmlTable inside the HtmlTableCell. When i want to get the value of the RadioButton if is it checked or not , i'm using the following codeRadioButton rbtn = (RadioButton)Page.FindControl(ID);The rbtn is always null knowing that if i check the Page source i find the RadioButton with the Same ID that I'm calling in the FindControl. Co...

How to get Textbox value in web user control?
Hi friends,I created a web user control with only one textbox.(textbox.ascx) and textbox id=" txtSimple"textbox user control having some property. another user control with button(button.ascx) next i use two textbox usercontrol and one button usercontrol in sample.aspx. when i click button at that time call the required field validate property in textbox user control.in property have following code.public bool RequireValidate    {        set        {     &nbs...

Get value from Gridview into textbox and dropDrownList controls
  Hi to all,I (newbie) want that when user click on ID field of Gridview.The values of that particular ID row should display in the textbox and dropdown list of the page.<asp:Label ID="lblAccessID" runat="server" Text="Access ID" Width="91px" Height="16px"></asp:Label>        <asp:TextBox ID="txtAccessID" runat="server" Height="12px" Width="126px"></asp:TextBox> <br /><br />        &l...

Setting and getting value problem from a IFrame control...
Hi everybody,   I having problem getting and setting values to and from a iframe control and javascript function that does these actions. Does anyone has ideas how to make this work? Is it possible to use ApplicationState, SessionState objects inside Javascript function? If not, how can these actions can be done?Error Message:A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$PostIdea_Function1$RichTextEditor1$hdnmsg="...peatedly. <STRONG>Forgot.</STR..."). Description: Request Validation has detected a potentially ...

Custom web control. Get Textbox.text value
Hi I have created a custom web control that extends the CheckBoxList control. It basically is a CheckBoxList control that has a TextBox added to the end of each CheckBox. It looks like the following after it has being bound to a database table column. I need to be able to retrieve the values in the corresponding TextBox when a CheckBox is selected. I tried storing each TextBox in an ArrayList but it is always empty when I try and check it. I am pretty new to ASP and am obviously missing something. Has anybody here got any tips or ideas on how I could retrieve the data from the TextBoxes...

Problem with getting the value from a Textbox to save into Access Database
Perhaps some one can help me with this problem. It seems simple enough, yet confusing at the same time. I’m working with this asp.net project where the user has the ability to click on the hyperlink column of a datagrid object and is forwarded to an updatinf web form. A querystring containing the ID of the record to update is passed to the new .aspx form as well. In the "Page_Load" method of the code behind file of the update form, we takes the record ID and successfully find the record in the database and populates the current form with the appropriate data. There is also a submi...

Cannot get value from an input textbox to a listbox web control??
I am about to go nuts because I really have not done any Asp.Net programming up until now. I have mainly done desktop applications. I am trying to take the textbox in the page and pass the contents of it to the listbox on the same page. I cannot get the values from the textbox to the listbox. Below is my code for the aspx page and also for my code behind page. Can someone please tell and show me where I am going wrong? aspx page:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AspNetPolyDraw.Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML...

Web resources about - Problem with getting the value from a textbox - asp.net.presentation-controls

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

The government’s surprising problem
Labor has powered up a savage campaign to punish Prime Minister Malcolm Turnbull for failure to meet a tax overhaul deadline — a deadline that ...

Android Marshmallow problems: troubleshooting guide
... a lot of great changes to Android, it's not without at least a few flaws. With that in mind, here are the major Android Marshmallow problems ...

Problems booting up Windows 10 Insider Preview Build 14267? Here's a quick fix
... 10 Insider Preview Redstone Build 14267 arrives on the Fast ring and brings welcome improvements If you’ve experienced this annoying problem ...

Amazon wants to accomplish a nearly-impossible task — and it's already plagued with problems
Amazon is detemined to take over the apparel industry. The brand is scooping up talented people in the fashion world for roles on its merchandising ...

Bill and Melinda Gates: Youth needed to help solve major world problems
Couple has made a ​tradition of releasing annual letter on philanthropy; this year's letter calls on young people to be a driving force for innovation ...

Kim Kardashian thinks Kanye West ‘just has a problem controlling his impulses’
... get it all out. Kanye might seem mentally unstable at times, but there has never been any concern for Kim, or the kids. Kanye just has a problem ...

$164 Per Mile: Surprise Ambulance Bills Are A Growing Problem & Difficult To Avoid
We’ve already seen that unconscious patients can end up with huge medical bills when an ambulance takes them to a hospital that doesn’t accept ...

Giardi: Is Hanley Ramirez ’taking it slow’ a problem?
... 36° Main menu Home Celtics Patriots Red Sox Bruins Revolution More WRITERS Watch Shop NECN Giardi: Is Hanley Ramirez ’taking it slow’ a problem? ...

Apple Pay runs into problem for its China launch
Apple Pay made its debut in China this Thursday, but things didn’t go quite as smoothly as hoped — largely thanks to the sheer number of users ...

Resources last updated: 2/23/2016 12:00:31 PM