473,789 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox losing value during DataGridCommand Event

Hello everyone. I am trying to write some custom command events into a
DataGrid. The command that is currently giving me trouble is an "Add"
custom command in the footer of a template column.

Question #1: In the Add button Command Event I am trying to access the
Text value of the TextBox in the other Footer columns. However, inside
the Event, the TextBox.Text values are all empty strings, even if they
had data typed into them. Is this a simple PostBack related error? I
have included a sample .aspx and .cs file that demonstrates my
difficulty. Here is the .aspx file:

<%@ Page language="c#" Codebehind="Tes t.aspx.cs"
AutoEventWireup ="false" Inherits="polar is.Test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD><title>Te st</title></HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateCol umns="False" ShowFooter="Tru e">
<columns>
<asp:templateco lumn headertext="Nam e">
<itemtemplate >
<asp:label id="Label1" runat="server" text='
<%# DataBinder.Eval (Container.Data Item, "Name") %>' />
</itemtemplate>
<footertemplate >
<asp:textbox id="Textbox1" runat="server" />
</footertemplate>
</asp:templatecol umn>
<asp:templateco lumn headertext="Act ion">
<itemtemplate >
<asp:linkbutt on commandname="Ed it" id="Button1"
runat="server" text="Edit" />
</itemtemplate>
<footertemplate >
<asp:linkbutt on commandname="Ad dSchedule" id="Button2"
runat="server" text="Add" />
</footertemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
<asp:Label id="Label2" runat="server" /><br />
<asp:Label id="Label3" runat="server" />
</form>
</body>
</HTML>
And here is the code behind:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace polaris
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Data Grid DataGrid1;
protected System.Web.UI.W ebControls.Labe l Label2;
protected System.Web.UI.W ebControls.Labe l Label3;

static DataTable oTable = new DataTable();

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!Page.IsPostBa ck)
{
oTable.Columns. Add("Name");
object[] R1 = new object[] { "John" };
object[] R2 = new object[] { "Jane" };
object[] R3 = new object[] { "Jack" };
object[] R4 = new object[] { "Jill" };
oTable.Rows.Add (R1);
oTable.Rows.Add (R2);
oTable.Rows.Add (R3);
oTable.Rows.Add (R4);
}
DataGrid1.DataS ource = oTable;
DataGrid1.DataB ind();
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
// Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.DataGrid1. ItemCommand += new
System.Web.UI.W ebControls.Data GridCommandEven tHandler
(this.DataGrid1 _ItemCommand);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion

private void DataGrid1_ItemC ommand(Object source,
DataGridCommand EventArgs e)
{
TextBox T1 = (TextBox)e.Item .FindControl("T extbox1");
Label2.Text = "Type: " + T1.Text.GetType ().ToString();
Label3.Text = "Value: " + T1.Text;
return;
}
}
}
This compiles and runs, and if you fill out a value in the footer
TextBox, then click the Add button, it should demonstrate the problem
with my first question. Any help is appreciated.
Question #2: Do I have to use a LinkButton control for this kind of
operation? When I switch the control to an asp:button type, it doesn't
seem to function at all.

Thanks in advance for any help,

Jason

Nov 19 '05 #1
0 1399

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2324
by: MLH | last post by:
Would like to examine the value entered into a textbox on an A97 form during the BeforeUpdate event. The textbox may or may not have had an earlier entry in it prior to the latest value that is now in the process of being entered. What's the best way to refer to the value just typed that is about to update the textbox?
1
4286
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number has an upper limit. I want to do validation on what the user enters as they type it in. I set up an event handler for KeyPress that restricts them from being able to enter non-numeric characters (only allowing numbers, decimal point, control...
5
5294
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the sessionstate inproc mode and users are randomly losing their session. I do not believe it is happening across all users at one time. It seems to happen to different users at different times, but I am only going off heresay. The aspnet worker...
7
2141
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
2
5899
by: Sridhar | last post by:
Hi, I have a user control which has a textbox control and a button. I have created a property to get and set the text box value. In the Page_Load method of the Page that contains the user control, I am setting the textbox value that is inside the user control. When I click the button that is inside the user control and try to access the textbox value it is getting empty string instead of the value set in the Page_Load. I have tried...
0
1069
by: Mr. SweatyFinger | last post by:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request. I have a "Create new ad" page with a formview1 that ties to the "ads" table, In this form I have a...
1
4232
by: jqheller | last post by:
Folks I am losing my mind trying to work with the TemplatedWizardStep. I have created a multistep user registration form that collects plenty of user information including a password. At the end of the process I am finding that the value of my password control is blank. When I set the textmode of my textbox to singleline, the value is preserved. It is just when the textbox is set to password that I lose the value. I am casting to the...
2
4259
by: =?Utf-8?B?TG91aXNhOTk=?= | last post by:
Hello. ive just read some posts on the age old issue of losing dynamic control values on postback. Most people say recreate the controls on the onInit, but i just dont think this serves my purpose. if i could explain: i have a list of reports in a datalist. a user clicks a report link. it goes off to reporting services, fetches the parameters for this report and displays x number of textboxes (and labels) for those parameters (hence it...
7
3090
by: adiel_g | last post by:
Hello Everyone, I created a custom control. On the CreateChildControls, I added a textbox to the control as follows: // TextBox TextBox txtValue = new TextBox(); txtValue.ID = "txtValue"; protected override void CreateChildControls() { // Add the control to the form
0
10410
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
10200
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...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
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
9020
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
7529
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
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.