Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Saturday, March 31, 2012

Text Box

I have a asp.net textbox on my page with a default value in it. I would like
the box to be cleared when some one clicks on the box.
How do I go about doing this?you need to add some client-side javascript like this:

onfocus=" if ( this.value == 'some default' ) this.value=''; " onblur="
if ( this.value == '' ) this.value = 'some default' ; "

Lou Civitella wrote:

Quote:

Originally Posted by

I have a asp.net textbox on my page with a default value in it. I would like
the box to be cleared when some one clicks on the box.
How do I go about doing this?

text box and SqlDecimal datatypes

Hi all, I have a DAL which takes in a value as shown below ready for my
MSSQL stored procedure.

protected SqlDecimal _annualLeave = SqlDecimal.Null;
public SqlDecimal AnnualLeave
{

get {return _annualLeave;}

set{ _annualLeave = value;}

}

I have a problem where when I try to pass in information from a textbox on a
ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!

I thought I could just go..

((System.Data.SqlDecimal)AnnualLeave.Text)

Where AnnualLeave.Text is the value of my textbox on my form, but I received
"Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
(Which is fair enough)

So, I tried

((System.Data.SqlDecimal)(Convert.ToDecimal(Annual Leave.Text))

but for some reason, this rounds the number to an integer!! e.g. 12.2
becomes 12!!!!!

Can someone please tell me what am I doing wrong here, it's been a long day
:P

Thanks
MarkHi Mark,

just use Convert.ToDecimal(AnnualLeave.Text)

HTH,

"Mark" <mark@.Z-Zvolution.nZt> wrote in message
news:OQXlCD24FHA.2364@.TK2MSFTNGP12.phx.gbl...
> Hi all, I have a DAL which takes in a value as shown below ready for my
> MSSQL stored procedure.
> protected SqlDecimal _annualLeave = SqlDecimal.Null;
> public SqlDecimal AnnualLeave
> {
> get {return _annualLeave;}
> set{ _annualLeave = value;}
> }
> I have a problem where when I try to pass in information from a textbox on
> a
> ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
> I thought I could just go..
> ((System.Data.SqlDecimal)AnnualLeave.Text)
> Where AnnualLeave.Text is the value of my textbox on my form, but I
> received
> "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
> (Which is fair enough)
> So, I tried
> ((System.Data.SqlDecimal)(Convert.ToDecimal(Annual Leave.Text))
> but for some reason, this rounds the number to an integer!! e.g. 12.2
> becomes 12!!!!!
> Can someone please tell me what am I doing wrong here, it's been a long
> day
> :P
> Thanks
> Mark
Hi Onin, I was actually doing this originally and still get the same
problem.

Thanks for your advice
Cheers
Mark
"Onin Tayson" <Leon_Tayson@.compaid.com> wrote in message
news:O%23qlxt44FHA.1140@.tk2msftngp13.phx.gbl...
> Hi Mark,
> just use Convert.ToDecimal(AnnualLeave.Text)
> HTH,
> "Mark" <mark@.Z-Zvolution.nZt> wrote in message
> news:OQXlCD24FHA.2364@.TK2MSFTNGP12.phx.gbl...
> > Hi all, I have a DAL which takes in a value as shown below ready for my
> > MSSQL stored procedure.
> > protected SqlDecimal _annualLeave = SqlDecimal.Null;
> > public SqlDecimal AnnualLeave
> > {
> > get {return _annualLeave;}
> > set{ _annualLeave = value;}
> > }
> > I have a problem where when I try to pass in information from a textbox
on
> > a
> > ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
> > I thought I could just go..
> > ((System.Data.SqlDecimal)AnnualLeave.Text)
> > Where AnnualLeave.Text is the value of my textbox on my form, but I
> > received
> > "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
> > (Which is fair enough)
> > So, I tried
> > ((System.Data.SqlDecimal)(Convert.ToDecimal(Annual Leave.Text))
> > but for some reason, this rounds the number to an integer!! e.g. 12.2
> > becomes 12!!!!!
> > Can someone please tell me what am I doing wrong here, it's been a long
> > day
> > :P
> > Thanks
> > Mark

text box and SqlDecimal datatypes

Hi all, I have a DAL which takes in a value as shown below ready for my
MSSQL stored procedure.
protected SqlDecimal _annualLeave = SqlDecimal.Null;
public SqlDecimal AnnualLeave
{
get {return _annualLeave;}
set{ _annualLeave = value;}
}
I have a problem where when I try to pass in information from a textbox on a
ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
I thought I could just go..
((System.Data.SqlDecimal)AnnualLeave.Text)
Where AnnualLeave.Text is the value of my textbox on my form, but I received
"Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
(Which is fair enough)
So, I tried
((System.Data.SqlDecimal)(Convert.ToDecimal(AnnualLeave.Text))
but for some reason, this rounds the number to an integer!! e.g. 12.2
becomes 12!!!!!
Can someone please tell me what am I doing wrong here, it's been a long day
:P
Thanks
MarkHi Mark,
just use Convert.ToDecimal(AnnualLeave.Text)
HTH,
"Mark" <mark@.Z-Zvolution.nZt> wrote in message
news:OQXlCD24FHA.2364@.TK2MSFTNGP12.phx.gbl...
> Hi all, I have a DAL which takes in a value as shown below ready for my
> MSSQL stored procedure.
> protected SqlDecimal _annualLeave = SqlDecimal.Null;
> public SqlDecimal AnnualLeave
> {
> get {return _annualLeave;}
> set{ _annualLeave = value;}
> }
> I have a problem where when I try to pass in information from a textbox on
> a
> ASP.NET page OR Winform the *damn* thing gets rounded to an Integer!
> I thought I could just go..
> ((System.Data.SqlDecimal)AnnualLeave.Text)
> Where AnnualLeave.Text is the value of my textbox on my form, but I
> received
> "Cannot convert type 'string' to 'System.Data.SqlTypes.SqlDecimal" error
> (Which is fair enough)
> So, I tried
> ((System.Data.SqlDecimal)(Convert.ToDecimal(AnnualLeave.Text))
> but for some reason, this rounds the number to an integer!! e.g. 12.2
> becomes 12!!!!!
> Can someone please tell me what am I doing wrong here, it's been a long
> day
> :P
> Thanks
> Mark
>
Hi Onin, I was actually doing this originally and still get the same
problem.
Thanks for your advice
Cheers
Mark
"Onin Tayson" <Leon_Tayson@.compaid.com> wrote in message
news:O%23qlxt44FHA.1140@.tk2msftngp13.phx.gbl...
> Hi Mark,
> just use Convert.ToDecimal(AnnualLeave.Text)
> HTH,
> "Mark" <mark@.Z-Zvolution.nZt> wrote in message
> news:OQXlCD24FHA.2364@.TK2MSFTNGP12.phx.gbl...
on
>

Text Box Loses Value On Page Load

Hi Folks...this is a wierd issue I've noticed and wanted to know of a) anyone
else has noticed this and b) if so, why does it happen.

On page load, I have a text box named me.txtMemberName. I enter data into
this field then submit the page. If I check the value of
me.txtMemberName.text during the page load event, it is an empty string. Now,
if I check this again in a later event, the value of .text has the correct
inforamation in it. This is causing me grief b/c, since this is a required
field, Page.IsValid is failing on page load. Any thoughts?

Thanks!

ClayFirst of all, I am assuming you have EnableViewState=True for this Control,
as well as for the Page. Second, can you post your Page.Load procedure so we
can see exactly what you do there and how you do it? This may help me and
others help you solve your problem. Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/

"Clayton Hoyt" <ClaytonHoyt@.discussions.microsoft.com> wrote in message
news:1D931693-325B-4116-901F-3D09CF24FE8C@.microsoft.com...
> Hi Folks...this is a wierd issue I've noticed and wanted to know of a)
> anyone
> else has noticed this and b) if so, why does it happen.
> On page load, I have a text box named me.txtMemberName. I enter data into
> this field then submit the page. If I check the value of
> me.txtMemberName.text during the page load event, it is an empty string.
> Now,
> if I check this again in a later event, the value of .text has the correct
> inforamation in it. This is causing me grief b/c, since this is a required
> field, Page.IsValid is failing on page load. Any thoughts?
> Thanks!
> Clay

Text box losing most recent Text value

It's me and my registration page again. I have a subroutine that calculates
the total fees the registrant will incur and puts it in a textbox (not a
label because it has to be passed to another page).
txtTotalFees.Text = Format(dblTotalFees, "Currency")
The subroutine works fine IF I call it from PageLoad, or I assign it to a
button for recalculating the total fees, or the user clicks the Reset
button, or if they click a control that has AutoPostback set to true.
Basically anything that loads or postbacks the page.
BUT...When it comes time to submit the page and go to the next page I have
this code:
If IsValid Then
CalcFees() 'recalcs fees and updates textbox
Server.Transfer("Confirmation.aspx", True)
End If
When the user gets to the next page I put the total fees in another textbox.
EXCEPT it isn't updated to most recent total. I know because I can comment
out the "Server.Transfer" so that it stays at the registration page AND THE
CORRECT TOTAL IS DISPLAYED!?!?!
What is it about the Server.Transfer that "forgets" what the value of the
textbox should be?
Ken "BiggMakk" McCroryHi Ken
Try this:
Server.Transfer("Confirmation.aspx", True)
This sets the parameter preserveForm to true, hence preserving any
variables still available.
You can then retrieve the value from your previous page on the
Confirmation.aspx page by using Request.Form("totalFees")
Hope that helps :)
sze
Thanks for the try but I am already using the True to preserve variables.
(See original post. It's there.)
Ken "BiggMakk" McCrory
"sze" <szeying.tan@.gmail.com> wrote in message
news:1110401185.776188.29550@.o13g2000cwo.googlegroups.com...
> Hi Ken
> Try this:
> Server.Transfer("Confirmation.aspx", True)
> This sets the parameter preserveForm to true, hence preserving any
> variables still available.
> You can then retrieve the value from your previous page on the
> Confirmation.aspx page by using Request.Form("totalFees")
> Hope that helps :)
> sze
>
Ah, sorry. I didn't notice it in your code at first glance.
Here's a helpful page from MSDN about preserving state between pages.
http://msdn.microsoft.com/library/d...etweenPages.asp
Hope that helps.
I solved this by using SmartNavigation and turning on Autopostback for every
control that can affect the total fees. Before someone says SmartNav doesn't
work in browsers other than IE, you're right. Someone else in a different
post of mine pointed out Smart Scroller by Strength Technologies at this web
site:
http://www.strengthtechnologies.com...l/Download.aspx
It works even in Firefox.
Now the Total fees gets updated before the user hits the Submit button and
the correct value gets passed to the next page. It also removes the need for
the manual "Recalculate Fees" button that I had on the page.
--
Ken "BiggMakk" McCrory
"Ken McCrory" <klm355t@.removefornospammers.smsu.edu> wrote in message
news:OjfvdfOJFHA.688@.TK2MSFTNGP10.phx.gbl...
> It's me and my registration page again. I have a subroutine that
> calculates the total fees the registrant will incur and puts it in a
> textbox (not a label because it has to be passed to another page).
> txtTotalFees.Text = Format(dblTotalFees, "Currency")
> The subroutine works fine IF I call it from PageLoad, or I assign it to a
> button for recalculating the total fees, or the user clicks the Reset
> button, or if they click a control that has AutoPostback set to true.
> Basically anything that loads or postbacks the page.
> BUT...When it comes time to submit the page and go to the next page I have
> this code:
> If IsValid Then
> CalcFees() 'recalcs fees and updates textbox
> Server.Transfer("Confirmation.aspx", True)
> End If
> When the user gets to the next page I put the total fees in another
> textbox. EXCEPT it isn't updated to most recent total. I know because I
> can comment out the "Server.Transfer" so that it stays at the registration
> page AND THE CORRECT TOTAL IS DISPLAYED!?!?!
> What is it about the Server.Transfer that "forgets" what the value of the
> textbox should be?
> Ken "BiggMakk" McCrory
>
Yeah Ken the control works with FireFox and I.E!!!
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Text box losing most recent Text value

It's me and my registration page again. I have a subroutine that calculates
the total fees the registrant will incur and puts it in a textbox (not a
label because it has to be passed to another page).

txtTotalFees.Text = Format(dblTotalFees, "Currency")

The subroutine works fine IF I call it from PageLoad, or I assign it to a
button for recalculating the total fees, or the user clicks the Reset
button, or if they click a control that has AutoPostback set to true.
Basically anything that loads or postbacks the page.

BUT...When it comes time to submit the page and go to the next page I have
this code:

If IsValid Then
CalcFees() 'recalcs fees and updates textbox
Server.Transfer("Confirmation.aspx", True)
End If

When the user gets to the next page I put the total fees in another textbox.
EXCEPT it isn't updated to most recent total. I know because I can comment
out the "Server.Transfer" so that it stays at the registration page AND THE
CORRECT TOTAL IS DISPLAYED!?!?!

What is it about the Server.Transfer that "forgets" what the value of the
textbox should be?

Ken "BiggMakk" McCroryHi Ken

Try this:
Server.Transfer("Confirmation.aspx", True)
This sets the parameter preserveForm to true, hence preserving any
variables still available.

You can then retrieve the value from your previous page on the
Confirmation.aspx page by using Request.Form("totalFees")

Hope that helps :)
sze
Thanks for the try but I am already using the True to preserve variables.
(See original post. It's there.)

Ken "BiggMakk" McCrory

"sze" <szeying.tan@.gmail.com> wrote in message
news:1110401185.776188.29550@.o13g2000cwo.googlegro ups.com...
> Hi Ken
> Try this:
> Server.Transfer("Confirmation.aspx", True)
> This sets the parameter preserveForm to true, hence preserving any
> variables still available.
> You can then retrieve the value from your previous page on the
> Confirmation.aspx page by using Request.Form("totalFees")
> Hope that helps :)
> sze
Ah, sorry. I didn't notice it in your code at first glance.

Here's a helpful page from MSDN about preserving state between pages.
http://msdn.microsoft.com/library/d...etweenPages.asp

Hope that helps.
I solved this by using SmartNavigation and turning on Autopostback for every
control that can affect the total fees. Before someone says SmartNav doesn't
work in browsers other than IE, you're right. Someone else in a different
post of mine pointed out Smart Scroller by Strength Technologies at this web
site:

http://www.strengthtechnologies.com...l/Download.aspx

It works even in Firefox.

Now the Total fees gets updated before the user hits the Submit button and
the correct value gets passed to the next page. It also removes the need for
the manual "Recalculate Fees" button that I had on the page.
--
Ken "BiggMakk" McCrory

"Ken McCrory" <klm355t@.removefornospammers.smsu.edu> wrote in message
news:OjfvdfOJFHA.688@.TK2MSFTNGP10.phx.gbl...
> It's me and my registration page again. I have a subroutine that
> calculates the total fees the registrant will incur and puts it in a
> textbox (not a label because it has to be passed to another page).
> txtTotalFees.Text = Format(dblTotalFees, "Currency")
> The subroutine works fine IF I call it from PageLoad, or I assign it to a
> button for recalculating the total fees, or the user clicks the Reset
> button, or if they click a control that has AutoPostback set to true.
> Basically anything that loads or postbacks the page.
> BUT...When it comes time to submit the page and go to the next page I have
> this code:
> If IsValid Then
> CalcFees() 'recalcs fees and updates textbox
> Server.Transfer("Confirmation.aspx", True)
> End If
> When the user gets to the next page I put the total fees in another
> textbox. EXCEPT it isn't updated to most recent total. I know because I
> can comment out the "Server.Transfer" so that it stays at the registration
> page AND THE CORRECT TOTAL IS DISPLAYED!?!?!
> What is it about the Server.Transfer that "forgets" what the value of the
> textbox should be?
> Ken "BiggMakk" McCrory
Yeah Ken the control works with FireFox and I.E!!!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Text Box Loses Value On Page Load

Hi Folks...this is a wierd issue I've noticed and wanted to know of a) anyon
e
else has noticed this and b) if so, why does it happen.
On page load, I have a text box named me.txtMemberName. I enter data into
this field then submit the page. If I check the value of
me.txtMemberName.text during the page load event, it is an empty string. Now
,
if I check this again in a later event, the value of .text has the correct
inforamation in it. This is causing me grief b/c, since this is a required
field, Page.IsValid is failing on page load. Any thoughts?
Thanks!
ClayFirst of all, I am assuming you have EnableViewState=True for this Control,
as well as for the Page. Second, can you post your Page.Load procedure so we
can see exactly what you do there and how you do it? This may help me and
others help you solve your problem. Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Clayton Hoyt" <ClaytonHoyt@.discussions.microsoft.com> wrote in message
news:1D931693-325B-4116-901F-3D09CF24FE8C@.microsoft.com...
> Hi Folks...this is a wierd issue I've noticed and wanted to know of a)
> anyone
> else has noticed this and b) if so, why does it happen.
> On page load, I have a text box named me.txtMemberName. I enter data into
> this field then submit the page. If I check the value of
> me.txtMemberName.text during the page load event, it is an empty string.
> Now,
> if I check this again in a later event, the value of .text has the correct
> inforamation in it. This is causing me grief b/c, since this is a required
> field, Page.IsValid is failing on page load. Any thoughts?
> Thanks!
> Clay

Text box reading old value

Hi i am trying to create a simple page that would allow users to edit there infromation that is stored on them,

It loads the information from the database fine and puts it into the textbox's but then on the "update" button it doesnt get the changed values

e.g

if the textbox was set on the page load to "bren" and then i changed it on the page to be "Hello" when i execute the onlclick function of the button it still reads as "bren"

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.Odbc;public partialclass user_userDetails : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!HttpContext.Current.User.Identity.Name.Contains(ConfigurationManager.AppSettings["siteGSTPrefix"])) {string userGuid = HttpContext.Current.User.Identity.Name; OdbcConnection detailsCon = sqlconnect.Connect(); OdbcCommand detailsCom =new OdbcCommand("SELECT tbl_usr.Username,tbl_usr_info.first_name,tbl_usr_info.second_name,tbl_usr_info.address_line_1,tbl_usr_info.address_line_2,tbl_usr_info.address_line_3,tbl_usr_info.post_code,tbl_usr_info.home_phone,tbl_usr_info.work_phone,tbl_usr_info.email_addy FROM tbl_usr INNER JOIN tbl_usr_info ON tbl_usr.usr_guid = tbl_usr_info.usr_guid WHERE tbl_usr.usr_guid='" + userGuid +"'", detailsCon); OdbcDataReader detRead = detailsCom.ExecuteReader();while (detRead.Read()) { userNote.Text ="Your Password is not displayed for security!"; userName.Text = detRead["Username"].ToString().Replace("#@dotnet.itags.org.","'"); fName.Text = detRead["first_name"].ToString().Replace("#@dotnet.itags.org.","'"); sName.Text = detRead["second_name"].ToString().Replace("#@dotnet.itags.org.","'"); aD1.Text = detRead["address_line_1"].ToString().Replace("#@dotnet.itags.org.","'"); aD2.Text = detRead["address_line_2"].ToString().Replace("#@dotnet.itags.org.","'"); aD3.Text = detRead["address_line_3"].ToString().Replace("#@dotnet.itags.org.","'"); pCode.Text = detRead["post_code"].ToString().Replace("#@dotnet.itags.org.","'"); hPhone.Text = detRead["home_phone"].ToString().Replace("#@dotnet.itags.org.","'"); wPhone.Text = detRead["work_phone"].ToString().Replace("#@dotnet.itags.org.","'"); eAddy.Text = detRead["email_addy"].ToString().Replace("#@dotnet.itags.org.","'"); } detRead.Close(); detailsCon.Close(); }else { Response.Redirect(FormsAuthentication.LoginUrl); } }protected void update_click(object sender, EventArgs e) {string userGuid = HttpContext.Current.User.Identity.Name;string passSettings =string.Empty; Response.Clear();if(userPass.Text.ToString() !="" && userPass.Text.ToString() !=null) { passSettings =" , tbl_usr.Password = '" + userPass.Text.ToString().Replace("'","#@dotnet.itags.org.") +"'"; } OdbcConnection detCon = sqlconnect.Connect(); OdbcCommand upCom =new OdbcCommand("UPDATE tbl_usr SET tbl_usr.Username = '" + userName.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' " + passSettings +" WHERE tbl_usr.usr_guid = '" + userGuid +"'", detCon); upCom.ExecuteNonQuery(); OdbcCommand upComInfo =new OdbcCommand("UPDATE tbl_usr_info SET tbl_usr_info.first_name = '" + fName.Text.Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.second_name = '" + sName.Text.Replace("'","#@dotnet.itags.org.").Trim() +"' , tbl_usr_info.address_line_1 = '" + aD1.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.address_line_2 = '" + aD2.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.address_line_3 = '" + aD3.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.post_code = '" + pCode.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.work_phone = '" + wPhone.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.home_phone = '" + hPhone.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' , tbl_usr_info.email_addy = '" + eAddy.Text.ToString().Replace("'","#@dotnet.itags.org.") +"' WHERE tbl_usr_info.usr_guid = '" + userGuid +"'", detCon); upComInfo.ExecuteNonQuery(); userNote.Text ="Your details have been updated"; }}


Thanks for your help in advance

Dan

your update_click is happening after the page_load. try changing the code you have in page_load to page_prerender and see if you are good to go.


i have treid to user it with IsPostBack but it doesnt work,

i didnt think that Page_load was re run when u clicked on a button and ran the function

Dan


Fixed it now thanks changed it to a !IsPostBack and it now works thanks

Text Box to change on focus... Possible?

Hi i was just wondering if it was possible to change a text boxes default value onFocus... I have a search bar and rather then put next to it search product here I wanted to have written in the text box as default Enter Product Code.. and then when the box is clicked on it clears this text away and has a blank textbox before they begin to type

Thanks in advance for any help given

Hey,

Yes, there are two ways to do it. There is a TextboxWatermarkExtender (in the AJAXControlToolkit), which renders the text and manages that automatically for you, or you can use manual javascript, simply by catching the focus and when the textbox value is equal to the watermark value, clear it. I don't have an example on-hand, but you should be able to find one.


Create a test ASPX and add following:


<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="Enter Here"></asp:TextBox> <br/>
</div>
</form>
<script language="javascript" type="text/javascript">
function ClearValue()
{
document.getElementById("<%=TextBox1.ClientID %>").value = "";
}
</script>


In Code Behind add following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Attributes.Add("OnFocus", "javascript:ClearValue();")
End Sub

Hope this will serve the purpose.


Code for the text box:

<input id="txtBox1" type="text" value="Some Default Value" onfocus="ClearTxt();" />

Javascript function to clear default value:

<script type="text/javascript">
function ClearTxt() {
document.getElementById("txtBox1").value = ""
}
</script>


you could use a javascript method like teh one shown here

http://www.urban75.org/tech/q024.html


Thanks alot guys for all the help


try this

tst.Attributes.Add("onFocus","ctrl = document.getElementById('tst');ctrl.value = '';")

replace both occurrences of tst with the name of the textbox


Hi sorry i know this is an old post but I was wondering, I managed to get this working the only little thing is if I click in the box it deletes the text (what I was looking for) but if I dont type anything and click away from the box it's still blank.. I was wondering if there was a way to refill the text box with the default text again

Thanks


Hey,

Attach to the client onblur event, that if the textbox's text length is zero, put the text back in the textbox.


I know I am a strong anti-Javascript developer, but using javascript to set properties of a form control is not a very good idea, especially if you consider accessibility issues. Rather, why not to attach labels to the text box, and/or use tool-tip feature for displaying user information. This is both, dynamic, on focus, as well as Accessible to challanged users.

Again, it is kind of personal opinion, but then you have to think about the accessibility issues at some point of time!

Wednesday, March 28, 2012

text box value does not match value on postback

Hi All,

I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.

Any ideas on what is happening here or how to fix this issue?

Thanks ALOT in advance.<allan.palmer@.cit.comwrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

Quote:

Originally Posted by

Any ideas on what is happening here or how to fix this issue?


Show your code...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
<allan.palmer@.cit.comwrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

Quote:

Originally Posted by

Hi All,
>
I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.
>
Any ideas on what is happening here or how to fix this issue?
>
Thanks ALOT in advance.


Hi Allan,

The "problem" is that the POST value of the textbox is set *before*
Page_Load, then you are putting a default value in there during Page_Load
(overwriting the POST value), then your button click event is fired and you
see the Page_Load value instead of the POST value.

In your Page_Load, only set the default value of the textbox on the initial
page load:

if (!IsPostBack)
{
// Set default value.
}

text box value does not match value on postback

Hi All,
I have a text box that is currently being set by a javascript function
as a running total. the javascript is working fine, as values are
changing the running total is being set correctly in the text box.
When the page is posted to the button OnClick event, the value of the
text box is what was previously defaulted as part of the Page_Load
event.
Any ideas on what is happening here or how to fix this issue?
Thanks ALOT in advance.<allan.palmer@.cit.com> wrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...

> Any ideas on what is happening here or how to fix this issue?
Show your code...
Mark Rae
ASP.NET MVP
http://www.markrae.net
<allan.palmer@.cit.com> wrote in message
news:9726ad9f-9d5a-4c98-8473-01645482697b@.e4g2000hsg.googlegroups.com...
> Hi All,
> I have a text box that is currently being set by a javascript function
> as a running total. the javascript is working fine, as values are
> changing the running total is being set correctly in the text box.
> When the page is posted to the button OnClick event, the value of the
> text box is what was previously defaulted as part of the Page_Load
> event.
> Any ideas on what is happening here or how to fix this issue?
> Thanks ALOT in advance.
Hi Allan,
The "problem" is that the POST value of the textbox is set *before*
Page_Load, then you are putting a default value in there during Page_Load
(overwriting the POST value), then your button click event is fired and you
see the Page_Load value instead of the POST value.
In your Page_Load, only set the default value of the textbox on the initial
page load:
if (!IsPostBack)
{
// Set default value.
}

Text Box Will Not Wrap Text

VWD 2005 Express. Visual Basic. I placed a text box control on my page. I set the wrap property to true. I assign a value to the text property from code behind. The text does not wrap, but instead disappears when it hits the right margin. The only way I seem to be able to get it to wrap is to set the text box control to "multiline." However, this puts up a scroll bar, which I do not want. I want the box to be single line and to wrap. What might I be doing wrong?

you cant wrap the text unless it's multiline...

You can (I think) remove the scrollbars though, but it will need to be multiline


You need multiline...

What exactly are you trying to do? Have you considered a listbox? How about a dropdownlist box?


Turns out that a label control served me better. Thanks.

text change on click event

Hello all
i have a problem with aspx page that have some textbox and a checkbox .
i put code onCheckBox1_CheckedChangedthat value of first textbox put in second textbox.
if i edit the value of first textbox then value should be update of second textbox.
I cant post the page so want to fire click event. my code is

privatevoid CheckBox1_CheckedChanged(object sender, System.EventArgs e)

{

TextBox2.Text=TextBox1.Text;

}

Is CheckBox1 autopostback set to true?
But if you want the textbox to automatically change the value of the second textbox without the checkbox, then you need to look into some javascript.
Zath

yes autopostback is true.

And i don want to use javascript. plz give me the solution in asp.net or C#.


i donot know if what think is useful but you can try
have you tried to place the code in the textbox event with adding if statement for the checkbox and use auto post back ... and see if that will help??!!!
but i think the JS is better for a client side operations to reduce the traffic on the server !!! let me know what you do!!

What code do you have in your page_load event? Is there anything there that manipulates the text box? remeber that the page_load event fires every time the page posts back.
smtraber
i tried this code in the check box method

IfMe.CheckBox1.Checked =TrueThen

Me.TextBox2.Text =Me.TextBox1.Text

EndIf
and the auto post back is true for the check box
now when i write the text and tick after that i will get the change !!!
Is that what you meant?


Your code is ok and fine
IfMe.CheckBox1.Checked =TrueThen

Me.TextBox2.Text =Me.TextBox1.Text

EndIf
but the problem is that when i change the value of textbox1 (after check clicked )
then also value should be change without post the form.



arvindharitus wrote:

but the problem is that when i change the value of textbox1 (after check clicked )
then also value should be change without post the form.

Unfortunately, you won't be able to have this event fire without posting the form back to the server unless you use javascript. If your textboxes are set to autopostback=true, then the post back and therefore text_changed event should fire as soon as one of your textboxes loses focus.
smtraber


Check out what's the state of the "enableviewstate" property of the controls you are using? If that is false then just change them to true. Smile [:)]

Text Control value doesnt update

I have created an aspx page which onload populates a dataset then binds various controls to the relevant columns. Then on editing one of the text boxes on the click of a button I want to update the database. I have tried various updates but to no avail. I have narrowed the problem down to that on stepping through the code the value held in memory doesnt recognise that the text held in the control has changed from the original text. Any Ideas.If you are initialising your text box values in the Page_Load event, you must enclose your code in the following IF block:
If Not IsPostBack Then
'
' Initialisation code goes here...
'
End If
Worked a treat cheers, how simple but id never have guessed.

Saturday, March 24, 2012

text rendering problems

Hi - I have some text (type text) values stored in a SQL d-base (2005). The text already has html tags embedded in them. When I bind a value to a textbox for example it escapes the HTML values and does not treat them properly in the browser. How can I tell .NET (or SQL Server, not sure what is escaping the tags) to treat HTML tags in the text like HTML tags. For example if I view source on my aspx page I get the following:

This should be a <b> BOLD </b>

Making it not bold and actually showing the <b> </b> in the browser.

thanks

Paritally it's because controls like the TextBox cant handle HTML tags.

Also, look in the DB.. what's in there? The <..> or <... It may be a matter of how you are saving it


Use this controlhttp://freetextbox.com or use Response.Write(sbuffer);

Hope this helps

Al


the db does not have the < in the table. However, if the textbox control can't handle HTML tags that is probably it. Although I do not know what can't handle means. I would have guessed that the server side control itself does not handle the html tag....it would just spit the value out and the browser would handle it.

as far as the freetext box I will look at that...thanks.


What I mean by "cant handle" is that HTML is ignored.

Things like TextBox dont use HTML, only plain text. <b> is unknown to a TextBox where a Label understands it and interprets it, or rather allows the browser to...

Thursday, March 22, 2012

Text Value in a TextBox inside Datagrid

i have a textbox in a template column in a datagrid, it displays the
initial value of the row, but when i change it remains with the
original value (it doesnt get the new value..)
i fill the CartTable programmatically with rows from a database binded
datagrid..
i cant figure out what is wroooong! hehe thanks for helping
here is my code:
TABLE CODE (in the page_load):
If Session("shop_cart") Is Nothing Then
CartTable = New DataTable
CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
ession("shop_cart") = CartTable
Else
CartTable = Session("shop_cart")
End If
BindBuy() 'this assign the datasource and execute DataBind()
DATAGRID CODE:
<asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
absolute; TOP: 576px" runat="server"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3"
Width="712px" AllowPaging="True" Font-Names="Tahoma"
Font-Size="X-Small" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#006699"></HeaderStyle>
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn DataField="Product"
HeaderText="Product"></asp:BoundColumn>
<asp:BoundColumn DataField="Line"
HeaderText="Line"></asp:BoundColumn>
<asp:BoundColumn DataField="Description"
HeaderText="Description"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
DataBinder.Eval(Container.DataItem, "Quantity") %>' >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price"
DataFormatString="{0:c}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Total">
<ItemTemplate>
<p>
<asp:Label runat="server" Text='<%#
System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container
.DataItem,
"Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
ID="Label8"/>
</p>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066"
BackColor="Silver" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
UPDATE BUTTON CODE:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim _item As DataGridItem
Dim dr As DataRow
For i = 0 To dgBuy.Items.Count - 1
_item = dgBuy.Items(i)
Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
dr = CartTable.Rows(i)
dr(3) = qtyTextBox.Text
Next
BindBuy()
End SubMake sure viewstate is on the page. Also, likely you'll only want to
populate the grid when "not page.ispostback", otherwise you'll be overwritin
g
any changes made to the data in the boxes.
"ismaelf@.gmail.com" wrote:

> i have a textbox in a template column in a datagrid, it displays the
> initial value of the row, but when i change it remains with the
> original value (it doesnt get the new value..)
> i fill the CartTable programmatically with rows from a database binded
> datagrid..
> i cant figure out what is wroooong! hehe thanks for helping
> here is my code:
> TABLE CODE (in the page_load):
> If Session("shop_cart") Is Nothing Then
> CartTable = New DataTable
> CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
> ession("shop_cart") = CartTable
> Else
> CartTable = Session("shop_cart")
> End If
> BindBuy() 'this assign the datasource and execute DataBind()
>
> DATAGRID CODE:
> <asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
> absolute; TOP: 576px" runat="server"
> BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
> BackColor="White" CellPadding="3"
> Width="712px" AllowPaging="True" Font-Names="Tahoma"
> Font-Size="X-Small" AutoGenerateColumns="False">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#669999"></SelectedItemStyle>
> <ItemStyle ForeColor="#000066"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#006699"></HeaderStyle>
> <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
> <Columns>
> <asp:ButtonColumn Text="Delete"
> CommandName="Delete"></asp:ButtonColumn>
> <asp:BoundColumn DataField="Product"
> HeaderText="Product"></asp:BoundColumn>
> <asp:BoundColumn DataField="Line"
> HeaderText="Line"></asp:BoundColumn>
> <asp:BoundColumn DataField="Description"
> HeaderText="Description"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Quantity">
> <ItemTemplate>
> <asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
> DataBinder.Eval(Container.DataItem, "Quantity") %>' >
> </asp:TextBox>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:BoundColumn DataField="Price" HeaderText="Price"
> DataFormatString="{0:c}"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Total">
> <ItemTemplate>
> <p>
> <asp:Label runat="server" Text='<%#
> System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Contain
er.DataItem,
> "Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
> ID="Label8"/>
> </p>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> BackColor="Silver" Mode="NumericPages"></PagerStyle>
> </asp:datagrid>
> UPDATE BUTTON CODE:
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim i As Integer
> Dim _item As DataGridItem
> Dim dr As DataRow
> For i = 0 To dgBuy.Items.Count - 1
> _item = dgBuy.Items(i)
> Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
> dr = CartTable.Rows(i)
> dr(3) = qtyTextBox.Text
> Next
> BindBuy()
> End Sub
>
thanks, i populate the table under not page.ispostback now.. and verify
the ViewState also and its enabled.. but i still have the same problem
of the textbox.. :(

Text value does not stay the same when updated...

Hello:

I am in a very weird situation and hope that someone can help me shed some light on this...

I have a form that contains two textboxes, in one text box it asks for the users first name, in the other textbox it shows a template message that will be sent to the user...

So in my code I have on


If page.ispostback = "false" Then
txttemplatemessage.text = "Hello " & txtfirstname.text & "<custom message goes here>"
End If

With the above code, when the form is updated and a custom message is inserted... It works just fine... But if you tried to make changes to the txtfirstname.text, it does not accept the changes since it checks for ispostback = "false"...

Then When I try the following:


txttemplatemessage.text = "Hello " & txtfirstname.text & "<custom message goes here>"

With the above code, when the form is udpated the custom message inserted in the actual txttemplatemessage, does not show, since it overrides with when the information is posted back... But the txtfirstname update works fine...

How can I make both of these work? While still keeping the same logic if possible... Any suggestions?A wild shot...


If page.ispostback = "false" Then

txttemplatemessage.text = "Hello " & txtfirstname.text & "<custom message goes here>"
Else

If txtfirstname.text <> String.Empty Then
txttemplatemessage.text = "Hello " & txtfirstname.text & "<custom message goes here>"
End if

End If


That would not work since during the post back it re-assigns the values back to txttemplatemessage... so if the user had changed the message in there, his updated changes would just disappear with the generic template again... Any other suggestions?

Text value of Dropdown.

How do you get the selected text of a dropdown box? Selectedvalue will get
you the value and selectedindex will get you the position, but how do you
get the text (it isn't selectedText).
Thanks,
TomHi tshad,
Try this:
yourDropDownList.SelectecItem.Text
Guillermo G.
----
--
Guillermo Gonzlez Arroyave :: MCP ASP.Net C# :: DCE4
"tshad" <tscheiderich@.ftsolutions.com> wrote in message news:OlXi9QVkFHA.146
4@.TK2MSFTNGP14.phx.gbl...
How do you get the selected text of a dropdown box? Selectedvalue will get
you the value and selectedindex will get you the position, but how do you
get the text (it isn't selectedText).
Thanks,
Tom
d1.SelectedItem.Text;
"tshad" wrote:

> How do you get the selected text of a dropdown box? Selectedvalue will g
et
> you the value and selectedindex will get you the position, but how do you
> get the text (it isn't selectedText).
> Thanks,
> Tom
>
>
Is DropDownList.SelectedItem.Value what you're looking for?
-Brock
DevelopMentor
http://staff.develop.com/ballen

> How do you get the selected text of a dropdown box? Selectedvalue
> will get you the value and selectedindex will get you the position,
> but how do you get the text (it isn't selectedText).
> Thanks,
> Tom
>
> Is DropDownList.SelectedItem.Value what you're looking for?
Oh! Indeed, DropDownList.SelectedItem.Text is what you're after. :S
-Brock
DevelopMentor
http://staff.develop.com/ballen
"HARI PRASD BARU" <HARIPRASDBARU@.discussions.microsoft.com> wrote in message
news:CB37336A-6424-4CF5-A175-C5F90A100150@.microsoft.com...
> d1.SelectedItem.Text;
That was it.
I can never seem to remember that when I need it.
I never understood why you have a SelectedValue, but not a SelectedText.
Thanks,
Tom
> "tshad" wrote:
>

Text value of Dropdown.

How do you get the selected text of a dropdown box? Selectedvalue will get
you the value and selectedindex will get you the position, but how do you
get the text (it isn't selectedText).

Thanks,

TomHi tshad,

Try this:

yourDropDownList.SelectecItem.Text

Guillermo G.

------------------------
Guillermo Gonzlez Arroyave :: MCP ASP.Net C# :: DCE4

"tshad" <tscheiderich@.ftsolutions.com> wrote in message news:OlXi9QVkFHA.1464@.TK2MSFTNGP14.phx.gbl...
How do you get the selected text of a dropdown box? Selectedvalue will get
you the value and selectedindex will get you the position, but how do you
get the text (it isn't selectedText).

Thanks,

Tom
d1.SelectedItem.Text;

"tshad" wrote:

> How do you get the selected text of a dropdown box? Selectedvalue will get
> you the value and selectedindex will get you the position, but how do you
> get the text (it isn't selectedText).
> Thanks,
> Tom
>
Is DropDownList.SelectedItem.Value what you're looking for?

-Brock
DevelopMentor
http://staff.develop.com/ballen

> How do you get the selected text of a dropdown box? Selectedvalue
> will get you the value and selectedindex will get you the position,
> but how do you get the text (it isn't selectedText).
> Thanks,
> Tom
> Is DropDownList.SelectedItem.Value what you're looking for?

Oh! Indeed, DropDownList.SelectedItem.Text is what you're after. :S

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi tshad,

Try this:

yourDropDownList.SelectecItem.Text

Guillermo G.

------------------------
Guillermo Gonzlez Arroyave :: MCP ASP.Net C# :: DCE4

"tshad" <tscheiderich@.ftsolutions.com> wrote in message news:OlXi9QVkFHA.1464@.TK2MSFTNGP14.phx.gbl...
How do you get the selected text of a dropdown box? Selectedvalue will get
you the value and selectedindex will get you the position, but how do you
get the text (it isn't selectedText).

Thanks,

Tom
d1.SelectedItem.Text;

"tshad" wrote:

> How do you get the selected text of a dropdown box? Selectedvalue will get
> you the value and selectedindex will get you the position, but how do you
> get the text (it isn't selectedText).
> Thanks,
> Tom
>
Is DropDownList.SelectedItem.Value what you're looking for?

-Brock
DevelopMentor
http://staff.develop.com/ballen

> How do you get the selected text of a dropdown box? Selectedvalue
> will get you the value and selectedindex will get you the position,
> but how do you get the text (it isn't selectedText).
> Thanks,
> Tom
> Is DropDownList.SelectedItem.Value what you're looking for?

Oh! Indeed, DropDownList.SelectedItem.Text is what you're after. :S

-Brock
DevelopMentor
http://staff.develop.com/ballen
"HARI PRASD BARU" <HARIPRASDBARU@.discussions.microsoft.com> wrote in message
news:CB37336A-6424-4CF5-A175-C5F90A100150@.microsoft.com...
> d1.SelectedItem.Text;

That was it.

I can never seem to remember that when I need it.

I never understood why you have a SelectedValue, but not a SelectedText.

Thanks,

Tom
> "tshad" wrote:
>> How do you get the selected text of a dropdown box? Selectedvalue will
>> get
>> you the value and selectedindex will get you the position, but how do you
>> get the text (it isn't selectedText).
>>
>> Thanks,
>>
>> Tom
>>
>>
>

Text Value in a TextBox inside Datagrid

i have a textbox in a template column in a datagrid, it displays the
initial value of the row, but when i change it remains with the
original value (it doesnt get the new value..)
i fill the CartTable programmatically with rows from a database binded
datagrid..
i cant figure out what is wroooong! hehe thanks for helping
here is my code:

TABLE CODE (in the page_load):
If Session("shop_cart") Is Nothing Then
CartTable = New DataTable
CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
ession("shop_cart") = CartTable
Else
CartTable = Session("shop_cart")
End If
BindBuy() 'this assign the datasource and execute DataBind()

DATAGRID CODE:
<asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
absolute; TOP: 576px" runat="server"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3"
Width="712px" AllowPaging="True" Font-Names="Tahoma"
Font-Size="X-Small" AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#669999"></SelectedItemStyle>
<ItemStyle ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#006699"></HeaderStyle>
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<Columns>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn DataField="Product"
HeaderText="Product"></asp:BoundColumn>
<asp:BoundColumn DataField="Line"
HeaderText="Line"></asp:BoundColumn>
<asp:BoundColumn DataField="Description"
HeaderText="Description"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
DataBinder.Eval(Container.DataItem, "Quantity") %>' >
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Price" HeaderText="Price"
DataFormatString="{0:c}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Total">
<ItemTemplate>
<p align="right">
<asp:Label runat="server" Text='<%#
System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container.D ataItem,
"Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
ID="Label8"/>
</p>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066"
BackColor="Silver" Mode="NumericPages"></PagerStyle>
</asp:datagrid
UPDATE BUTTON CODE:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim _item As DataGridItem
Dim dr As DataRow

For i = 0 To dgBuy.Items.Count - 1

_item = dgBuy.Items(i)
Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
dr = CartTable.Rows(i)
dr(3) = qtyTextBox.Text

Next
BindBuy()

End SubMake sure viewstate is on the page. Also, likely you'll only want to
populate the grid when "not page.ispostback", otherwise you'll be overwriting
any changes made to the data in the boxes.

"ismaelf@.gmail.com" wrote:

> i have a textbox in a template column in a datagrid, it displays the
> initial value of the row, but when i change it remains with the
> original value (it doesnt get the new value..)
> i fill the CartTable programmatically with rows from a database binded
> datagrid..
> i cant figure out what is wroooong! hehe thanks for helping
> here is my code:
> TABLE CODE (in the page_load):
> If Session("shop_cart") Is Nothing Then
> CartTable = New DataTable
> CartTable.Columns.Add(New DataColumn("Product", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Line", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Description", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Quantity", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Price", GetType(String)))
> CartTable.Columns.Add(New DataColumn("Total", GetType(String)))
> ession("shop_cart") = CartTable
> Else
> CartTable = Session("shop_cart")
> End If
> BindBuy() 'this assign the datasource and execute DataBind()
>
> DATAGRID CODE:
> <asp:datagrid id="dgBuy" style="Z-INDEX: 103; LEFT: 80px; POSITION:
> absolute; TOP: 576px" runat="server"
> BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
> BackColor="White" CellPadding="3"
> Width="712px" AllowPaging="True" Font-Names="Tahoma"
> Font-Size="X-Small" AutoGenerateColumns="False">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#669999"></SelectedItemStyle>
> <ItemStyle ForeColor="#000066"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#006699"></HeaderStyle>
> <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
> <Columns>
> <asp:ButtonColumn Text="Delete"
> CommandName="Delete"></asp:ButtonColumn>
> <asp:BoundColumn DataField="Product"
> HeaderText="Product"></asp:BoundColumn>
> <asp:BoundColumn DataField="Line"
> HeaderText="Line"></asp:BoundColumn>
> <asp:BoundColumn DataField="Description"
> HeaderText="Description"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Quantity">
> <ItemTemplate>
> <asp:TextBox id=txtQty runat="server" Width="40px" Text='<%#
> DataBinder.Eval(Container.DataItem, "Quantity") %>' >
> </asp:TextBox>
> </ItemTemplate>
> </asp:TemplateColumn>
> <asp:BoundColumn DataField="Price" HeaderText="Price"
> DataFormatString="{0:c}"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Total">
> <ItemTemplate>
> <p align="right">
> <asp:Label runat="server" Text='<%#
> System.String.Format("{0:c}",CalcTotal(Int32.Parse(DataBinder.Eval(Container.D ataItem,
> "Quantity")),DataBinder.Eval(Container.DataItem, "Price"))) %>'
> ID="Label8"/>
> </p>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> <PagerStyle HorizontalAlign="Left" ForeColor="#000066"
> BackColor="Silver" Mode="NumericPages"></PagerStyle>
> </asp:datagrid>
> UPDATE BUTTON CODE:
> Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
> Dim i As Integer
> Dim _item As DataGridItem
> Dim dr As DataRow
> For i = 0 To dgBuy.Items.Count - 1
> _item = dgBuy.Items(i)
> Dim qtyTextBox As TextBox = _item.FindControl("txtQty")
> dr = CartTable.Rows(i)
> dr(3) = qtyTextBox.Text
> Next
> BindBuy()
> End Sub
>
thanks, i populate the table under not page.ispostback now.. and verify
the ViewState also and its enabled.. but i still have the same problem
of the textbox.. :(