Showing posts with label cant. Show all posts
Showing posts with label cant. Show all posts

Saturday, March 31, 2012

Trim the first character

How do i trim the first character.
I have string $22.22 and i want to be left with 22.22
I cant use subString(int,int) because i dont know the length of the stringYou can determine the length using the .Length property. So you can trim in C# like this:
string s = "$22.22";
s = s.Substring(1, s.Length - 1);
's' will now be "22.22"
There is also an overloaded substring method that only requires the starting character position:

strimmed=s.substring(1)

Tuesday, March 13, 2012

Troubles displaying a changing read-only value

I am writing a form with one value being a total of a couple other values from my page. I put this in a read-only textbox so it can't be changed, and when I change the other boxes values, the JavaScript automatically changes this value. However, when I generate the e-mail I use textboxTotalSpace.text to make it appear in my email, but this will only display the original value, and not the new one.

Does anyone know how I fix this?

Thanks.

TextBox server control will not pick up the changed values (during LoadPostData()) if the textbox is set to read only. Check this link for a fix:

http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx

Hope this helps,

Vivek


Thanks Vivek, but I am unsure where I am supposed to add theTextBox1.Attributes.Add("readonly","readonly")


That should go in the Page_Load event.

protected void Page_Load(object sender, EventArgs e)
{
// add the javascript attributes
TextBox1.Attributes.Add("readonly", "readonly");
}

Thanks


Because you are changing data at client side using java script....


You can put this in the Page Load method.


suresh modiya:

Because you are changing data at client side using java script....

Changed text box value client side WILL show up in the server code behind because textbox implements IPostBackDataHandler interface and it loads its value from the forms POST data in the LoadPostBackData() method.

Its only when it is set to readonly that this data load will not work on postback, hence the alternative.

Vivek