Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data manipulation within an EditItemTemplate field on Autopostback

Status
Not open for further replies.

Dijital

MIS
Mar 15, 2002
47
US
I'm writing a small app to track the assets within our organization. When editing an existing record (in a detailsview form) I have three fields: Purch_Month, Purch_Year and Repl_Year.
The first two (Purch x 2) are already populated when the record is created outside the app. When editing the record though, I want the form to do one of two things:

1) if the Repl_Year is NULL --> Set Repl_Year = Purch_Year + 3.
2) if Purch_Year is changed, it triggers an autopostback, which should trigger an eval on Repl_year to update that value as is example 1 (ie, Set Repl_Year = Purch_Year + 3).

I think I know how to do he page load triggers etc, but I really have no ide on how to address the edititemtemplatefield.

Any assistance (or even a mention of a better path to the same ends) would be appreciated.

Thanks!

Jim
 
you can calculate the initial replenishment value when the page first loads
Code:
if(replace value is empty)
{
   ReplenishmentTextBox.Text = (purchaseYear+3).ToString();
}
after that I would use javascript (jquery) to do the calculation. since webforms produces hideous client ids I would assign a unqiue css class to identify the control. here is an example
Code:
<asp:Textbox id... CssClass="purchase-year"/>
<asp:Textbox id... CssClass="replace-year"/>
and the jquery
Code:
$(function(){
   $('.purchase-year').blur(function(){
       $('.replace-year').val(this.value+3);
   });
});
requests to the server simply to add 2 numbers would not allow for a good user experience. You *could* use ajax to get back to the server, but again, that's overkill for basic math.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top