r/ASPNET • u/Mahbam42 • Mar 19 '12
[Question] Is there a better way to do autopostback="true"
I'm using VB in the code behind to calculate a total. Right now there is a text box for the quantity and then the math is all hard coded. In order for the event to fire without needing the enter key I added autopostback="true" to the quantity text box, but it causes the whole page to reload when the values change. Is there a better way to get the same results without reloading the page?
I'm super new to .net and have never worked in vb before, so my boss wants me to do simple stuff like this with just vb to practice and to get me familiar with it.
Edit: clarity
5
u/xTRUMANx Mar 19 '12
Out of curiosity, do you have any idea why your boss wants a pure vb.net solution?
You'll notice heseov solution doesn't require you to write any javascript but javascript is indeed involved for the solution. If your boss wants a pure vb.net solution because he's worried some folks will have javascript disabled then even heseov solution won't work.
The only other reason I can think of that he doesn't want javascript involved is because he's worried about maintenance when none of the staff knows javascript. However, if that is indeed the case, please make an effort to convince him to use this as an opportunity for the staff to get accustomed to javascript. If you're building websites, even with ASP.NET, one has to know the basic building blocks that is HTML, CSS and JS. Trying to let ASP.NET abstract that all a way is not a Good Thing.
3
u/heseov Mar 19 '12
You need to do ajax if you dont want to reload the page and that is only possible with javascript. You can get asp.net to write out all the needed javascript with an update panel so you dont have to write a line of js yourself. You just wrap your form in an update panel like this:
I guess an alternative would be an iframe but I dont recommend those.
2
u/Mahbam42 Mar 19 '12
If it helps any here is what I have so far,
Front End:
And code behind:
0
u/Jammb Mar 20 '12
Just wanted to add here, that although it's a personal preference, many developers prefer C# over VB.Net.
I wouldn't mention it except that if you're a javascript developer trying to get into ASP.NET, C# might be easier for you as it's much closer syntactically to javascript than VB is.