Need some help setting this up once in code behind and calling thru-out the page as needed

I have a form that do some calculations based on selection made..

Here is what i have as part of my event: ( this is just part of it..)

Regex rx = new Regex(@"(^\d*\.?\d*[1-9]+\d*$)|(^[1-9]+\d*\.\d*$)");

//String to test
string reg = amount1.Text;

if (rx.IsMatch(reg))


decimal r1, r2, r3, r4, tot;

if (amount1.Text != "") { r1 = decimal.Parse(amount1.Text); } else { r1 = 0; }

if (amount2.Text != "") { r2 = decimal.Parse(amount2.Text); } else { r2 = 0; }

if (amount3.Text != "") { r3 = decimal.Parse(amount3.Text); } else { r3 = 0; }

if (amount4.Text != "") { r4 = decimal.Parse(amount4.Text); } else { r4 = 0; }

tot = (r1 + r2 + r3 + r4);

I have seen some other pages within our project that have public string and public void setup and then called later on within the page, can i not setup the above to expect 1 or all 4 amounts and have it return that variable   "tot"

Here is one that is setup
public void InsertCharge(int vcID, string accountCode, double amount, int costCenter)

But that one is not returning anything.. its inserting the data..

right now i have that code within each of my events that i want to do the calculations.. so if i need to change anything i have to go thru the entire page and change it.. i want to be able and change in one place..

can anyone help?

Newbie to, Using VS2008 with C# and SQL2005
3/27/2009 4:40:49 PM 93655 articles. 5 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 11

 Yeah, make it a function and call it during the event you want.

"Hokey religions and ancient weapons are no match for a good blaster at your side."
3/27/2009 7:11:56 PM

 You could turn lines like this:

if (amount1.Text != "") { r1 = decimal.Parse(amount1.Text); } else { r1 = 0; }



public decimal CheckValue(sting Value)
   decimal convertedValue;

   if (!String.IsNullOrEmpty(Value))
      convertedValue = decimal.Parse(Value);
      convertedValue = 0.0;

   return convertedValue;


To be honest the else statement is not required because decimal starts
out as 0.0 anyway but it doesnt hurt to be explicit about what you are doing.

Then you could cut this:

decimal r1, r2, r3, r4, tot;

if (amount1.Text != "") { r1 = decimal.Parse(amount1.Text); } else { r1 = 0; }

if (amount2.Text != "") { r2 = decimal.Parse(amount2.Text); } else { r2 = 0; }

if (amount3.Text != "") { r3 = decimal.Parse(amount3.Text); } else { r3 = 0; }

if (amount4.Text != "") { r4 = decimal.Parse(amount4.Text); } else { r4 = 0; }

tot = (r1 + r2 + r3 + r4);

Down to this


decimal r1, r2, r3, r4, tot;

r1 = CheckValue(amount1.Text);
r2 = CheckValue(amount2.Text);
r3 = CheckValue(amount3.Text);
r4 = CheckValue(amount4.Text);

tot = (r1 + r2 + r3 + r4);

3/27/2009 7:33:41 PM

Similar Artilces:

Need help with setting credentials for calling Managed Web Hosting web services
Helllo, Can please someone help mi with some ASP.NET code sample for calling Managed Web Hosting::CreateAppPool or Managed Web Hosting::CreateCustomerWebSite.I am getting error "System.Net.WebException: The request failed with HTTP status 401: Unauthorized. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)" when calling  Managed Web Hosting::CreateAppPool  I guess something is wrong with credential parameters. Some parameter...? Thank's for help. My...

Setting width for .net controls in code(.aspx) page using function call in code behind..
Hi,  Currently I am trying to set the width of the Table as follows. <asp:Table width="<%=GetWidth()%>" >   and code behind protected Unit GetWidth() { return Unit.Percentage(50); }     It's not working. I know that it works if I set the width complete on some page event(like page_load) of code behind....   Is there a way to maintain the same syntax like calling code behind function in design page...i.e. calling function of .aspx.cs in .aspx page and assign the width as shown above.   Thanks and regards, Giridhar...

need help on code for not copying in web pages
hello, i need a code that will limit the user in using web pages to not copy the text on the page. i have seen it in sites and know it exists but don't know how to do it. Can anyone help? Thanx mona ali I don't suggest you to fight with windmills. You cannot avoid visitor to copy text on your web page unless you don't show your page to visitor. Visitor can anytime save the page and open it in his or her local computer with notepad and take text with copy and paste. Notepad doesn't render text and it doesn't run any JavaScript that blocks copy-paste actions. Also vi...

how can i convert code behind web forms pages to inline code pages
hi all of you, I have a problem, a have registered a free space at Brinkster , so i can just upload my files there one by one, but can not install my web application directly, and i have to upload my projects there, so one way is o convert all my VS.NET web application which is code behind, convert that into inline code, so how can i do that Thanks in advanceWarm Regards,Prajesh Kumar JhaE-MAIL : Convert from Code-Behind to Code-Inline: Darrell Norton, MVPDarrell Norton's BlogPlease m...

need help on displaying a web page in a PlaceHolder on a form
Can anyone provide a snipet of code to displaying a web page in a PlaceHolder on a form. I am pretty sure you can't load a full page into a placeholder, you would need to use an iFrame if you wanted to load a page into the middle of a webform. Hope this helps.Andrew L. Van You have to 'screen scrape' the page you want to display and place the retrieve html into your placeholder.  It is easier than you think.  See:       tenholde...

Need help on a web service call from a Windows Form
Hi there, I have created a small web service and a method that return a simple XML string - with no parameters attached. Now, I'm trying to write a function (say a button click) that will call this webservice.webmethod and display XML string (only: "<root><nodes><node>A</node><node>B</node><node>B</node></nodes></root>") How can I do this... Please help.  --- Web service code: start ------ using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.We...

Help Needed
Hi, In my web application, I have a confirmation message box (with OK and Cancel buttons) in Javascript which would be triggered if the user closes the page or hit the back button in the browser without submitting the selected data. If user hits 'OK', the page would be closed (or navigated away). Clicking 'Cancel' leaves user in the same page. Upto this it's working fine. In my page, the following is the functionality done: On selecting a record in a grid, that row would be locked for editing by the user. The lock would be released only on the 'Submit' button click. My requirement is ...

i need the code to set a page as home page upon page load
i need the code to set aspx page as home page upon page load I searched and dont know if i am not using the right wording but i cant find anything on this.. Thanks  Applciation Developer you ask a question, remember to click "mark as answered" when you get a reply which answers your question.My latest ASP.NET AJAX blog entries....

Get web page HTML source code
Hi there, i'm newbie in ASP.NET. I need to read/get web page HTML source in my program using ASP.NET. I've tried few ways but still can't get the result, including innerHTML, view-source, etc etc. Is anybody there can help me out? the reading page should consider of if the webpage content got scripts. thanks a lot for the help.... i really need u guys to guide me here. thanksregards, kelly lee what do do want to do with the html content ? kind regards piet do you mean from a remote site?RTFM - straight talk for web developers. Unmoderated, uncensored, occasionall...

Web form and a gridview on the same page with data validators
I have a form where a user can submit a new customer and directly below that is a gridview where they can view the customer they just submited plus their other customers they have submited in the past. Now this gridview has the edit/update property so the user can modify their customer information. The whole idea is to have 1 single page where a user can do everything they need to without having to be linked to another page. On this page we can submit new customer info and view the status/info of existing customers and edit that info as needed. So far that works fine. I can submit the new c...

Really need help with disabled web forms in visual 2003
Hi, I've posted in the ASP.NET forum as someone suggested, but I got no response and am still unable to use the software. In Visual Studio .NET 2003, with .NET Framework 1.1, all web form controls (in fact all controls in the toolbar) are disabled. I create a webform.aspx page, I AM in design view, but when I go to the "web forms" toolbar, I cannot drag anything to the page because all the controls are disabled (the toolbar is visible, just everything within it is disabled). I solved this last time by completely wiping my drive and spending three days reinstalling and updating everythin...

Need to position a table in the top left of page
Sorry, two questions here.  I'm making a master page and I want the standard layout with a top section, a left nav section, a right content section, and a bottom "about" section.  So I have a table with 3 rows, and 2 columns.  Row 1 has the columns merged, row 3 is the same and row 2 will have the first column at about 15% width and a nav tree while column 2 will be the actual content for all the other pages.   This all seems to work well except that the table always appears in the center of an IE window when I render it.  I want it to start in the ...

Need help w/web search form that would create an sql query w/results being shown on a new page in a datagrid
I'm new to ASP (see BIO for my knowledge base).  I'm trying to create a basic e-com site with a search similar to say or more applicable to my subject matter  I don't quite understand exactly how to create a search that will query my sql database and post back matching results to a different page that could then have x items per page with multiple pages. What I do get: I need a form to pick all the search criteria with (I have made this w/CheckBox, DropDownList & TextBox items) I need to create code (pref in C#) to send this info ...

Need help to make a page that can be uppdated from a web page.
Hello, I want to make a page that displays news. The page should be updated from another web page. I have tried several examples but cannot get the darn thing to work. I have a database file in Access that holds the short news articles but need help to make the code that updates and displays the articles. Can anybody point me to a tutorial that actually works please? Any help would be greatly appreciated. Regards Mic7 Hello: You will first need to learn ADO/ADO.NET, once you have learned how to do simple Select, update, delete statements... Heres a ...

Web resources about - Need some help setting this up once in code behind and calling thru-out the page as needed -

Resources last updated: 11/25/2015 7:04:25 AM