Showing posts with label together. Show all posts
Showing posts with label together. Show all posts

Monday, March 26, 2012

Performing multiplication in web form??

I need to multiply two numbers together on a web form and I have no idea how to do that. Here is the code that I wrote to try to perform this calculation:

if (txtQuantity.Text != null)
{
lblPrice.Text = intPrice * intQuantity;
}

I'm sure this is simple enough, but I'm new to ASP.NET and C# and not sure how this is supposed to work. Both values are coming from, as you can see, txtQuantity.text and lblPrice.text, both of which are strings. I found a couple of explanations about performing calculations online, but it was clearly written for more advanced users. A code sample would be great!

Take care


if (txtQuantity.Text != null)
{
lblPrice.Text = (intPrice * intQuantity).ToString();
}

How do I put txtQuantity.text and lblPrice.text into the variables. I just tried and I get an "cannot convert string to int" error.

Take care


long q=int.Parse(txtQuantity.Text);
long p=int.Parse(txtPrice.Text);

Note that int.Parse() will throw an exception if txtQuantity.Text is, say, "Fred" or "Hi" rather than something that can be parsed as a number.

Friday, March 16, 2012

persist xml in class referenced in asp.net page

hello I am putting together a web form which builds an xml file.
I have another class which is referenced in the asp.net page.
The first page load creates an instance of the class. In the class
are various methods which build up an xml file...ie create method
builds the
first root element, and other calls add elements and attributes to
this base root node.
The webpage has various buttons, dropdowns, and other controls which
when clicked on perform the various methods.
Now I could write the current XML to a filestore after each method in
my separate class file ie, Create root node, add elements, add
attributes, but I would rather persist an xmldocument object in the
class somehow.
However my asp.net page doesn't hold the properties of the first call
to the separate class into the second call. So if I instanciate my
class on the first page load, and don't recreate it on postback, if in
after CreateRoot() method called after the first button click, I call
an AddElement() method after another event, the xmldocument object
doesn't have its root node anymore.
Is there anyway a class can do this for an asp.net page, persist xml
between multiple postbacks, or is this by nature not possible due to
the fact that asp.net destroys all objects when it unloads?
Any clarification appreciated, I am attempting to build some
EnterpriseServices around the generation of Xml Template based
system...
Thanks,
yurpsIn article <984bebc3.0406220557.1044e41f@.posting.google.com>,
yurps@.yahoo.co.uk says...
> Is there anyway a class can do this for an asp.net page, persist xml
> between multiple postbacks, or is this by nature not possible due to
> the fact that asp.net destroys all objects when it unloads?
Look into the ViewState:
"Saving Web Forms Page Values Using View State"
http://tinyurl.com/2a8ns
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

persist xml in class referenced in asp.net page

hello I am putting together a web form which builds an xml file.

I have another class which is referenced in the asp.net page.
The first page load creates an instance of the class. In the class
are various methods which build up an xml file...ie create method
builds the
first root element, and other calls add elements and attributes to
this base root node.

The webpage has various buttons, dropdowns, and other controls which
when clicked on perform the various methods.

Now I could write the current XML to a filestore after each method in
my separate class file ie, Create root node, add elements, add
attributes, but I would rather persist an xmldocument object in the
class somehow.

However my asp.net page doesn't hold the properties of the first call
to the separate class into the second call. So if I instanciate my
class on the first page load, and don't recreate it on postback, if in
after CreateRoot() method called after the first button click, I call
an AddElement() method after another event, the xmldocument object
doesn't have its root node anymore.

Is there anyway a class can do this for an asp.net page, persist xml
between multiple postbacks, or is this by nature not possible due to
the fact that asp.net destroys all objects when it unloads?

Any clarification appreciated, I am attempting to build some
EnterpriseServices around the generation of Xml Template based
system...

Thanks,
yurpsIn article <984bebc3.0406220557.1044e41f@.posting.google.com>,
yurps@.yahoo.co.uk says...
> Is there anyway a class can do this for an asp.net page, persist xml
> between multiple postbacks, or is this by nature not possible due to
> the fact that asp.net destroys all objects when it unloads?

Look into the ViewState:

"Saving Web Forms Page Values Using View State"
http://tinyurl.com/2a8ns

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele