Work around for autopostback in ASP.NET

I am having performance issues on an ASP.NET page. It has a lot of data - and is using autopostbacks for some fields. I need to create a faster way to do this. Any suggestions?

This is what needs to happen:

The page needs to be able to display and correctly save numeric values that may need to be converted to metric values. The data is ALWAYS STORED IN US values (with 4 decimal place accuracy). For example, if the value is 12 feet, the value stored in the database is 12. If the user that is viewing the page has a login type of Canadian, then this page will need to convert the 12 Feet to the appropriate number of Meters and display that. When the user saves the page, the value in this field will need to be converted to FEET and saved.

The way that I am currently doing this is to have a hidden label field on the form and load the database value into this form on page load. I have an onchange event for this textbox that causes any entered value to be stored in the hidden field (and converted to US value (feet)  if this is a Canadian user) I have an autopostback on this field.

My solution works great - except that there is a huge performance problem.

Is there a way to accomplish this in Javascript?
pmacmannAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jpontaniCommented:
<script language="javascript">
function toMeters(vFeet) {
      return ((vFeet * 12 * 2.54) / 100);
}

function toFeet(vMeter) {
      return (vMeter * 100 / 2.54 / 12);
}
</script>

- Joe
0
pmacmannAuthor Commented:
Since I need to do this on change of the initial text field, what do I need to do to make this happen.

I have in my aspx page:

<asp:textbox runat=server id="txtAmount"></asp:textbox>
<asp:Label runat=server id="lblHiddenAmount"></asp:label>
0
jpontaniCommented:
<HTML>
<HEAD>
<script language="javascript">
var curType = 1; // 0 will be English, 1 will be Metric

function load() {
      if(curType == 1) { document.getElementById("nunit").innerText = "feet"; document.getElementById("ounit").innerText = "meters"; }
      else if(curType == 0) { document.getElementById("nunit").innerText = "meters"; document.getElementById("ounit").innerText = "feet"; }
}

function changeValue(myItem, newItem) {
      var myNewItem = document.getElementById(newItem);
      if(curType == 0) {
            myNewItem.innerText = toMeters(myItem.value);
      } else if (curType == 1) {
            myNewItem.innerText = toFeet(myItem.value);
      }
}

function toMeters(vFeet) {
     return Math.ceil(vFeet * 12 * 2.54 / 100);
}

function toFeet(vMeter) {
     return Math.ceil(vMeter * 100 / 2.54 / 12);
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onload="load()">
<form id="Form1" method="post" runat="server">
      <asp:textbox runat=server id="txtAmount" onchange="changeValue(this, 'txtHiddenAmount')"></asp:textbox>&nbsp;<span id="ounit"></span>
      <br>
      <asp:Label runat=server id="txtHiddenAmount"></asp:Label>&nbsp;<span id="nunit"></span>
</form>
</body>
</HTML>

That's a demo bit.

HTH,
- Joe
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pmacmannAuthor Commented:
The determination whether this user is US or Canadian is stored in a Session variable - does Javascript have access to this value? If not, I could store this value ( Session("CulturePref") ) in another hidden field - and then can Javascript access this field to determine if a conversion is necessary?

Thanks
0
jpontaniCommented:
In your javascript code, just do

var curtype = <%=Session("CulturePref")%>

or modify the script in they aren't 0/1 to determine which is which.

- Joe
0
pmacmannAuthor Commented:
Excellent! Works like a charm. One more question... let's say that the hidden value stored is 12.0001 and the value displayed is 12.00

If the user (who would be US at this time) wants the 12.00 value (not the 12.0001 value) - if the user enters 12.00 in the txt field - the onchange event doesn't fire because this is the same value. Is there a method besides onchange that will fire if the user enters anything into the field?
0
jpontaniCommented:
Yes, put it to onkeyup.

Note that putting onkeyup will fire after every keypress inside that field, so if the person types in 12345, it will fire after 1, then after 2 (reading 12), then after 3 (reading 123), and so on, but it will fire no matter if they type in the same value as before.

- Joe
0
pmacmannAuthor Commented:
OK - thanks for your assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.