Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have an aspx file, in which there are multiple asp controls and HTML controls, and there are both code-behind and JavaScript events and functions. In debugging, I enter some values. When I click a enter or return control, all of the HTML controls values are set back to its default (or starting scenario), while the asp controls' values are still there. I used F12 tool in debugging, but could not detect what is wrong in my JavaScript. Any hint? Thanks.

What I have tried:

All of the HTML controls' values got wiped out but asp controls' values are kept
Posted
Updated 24-Mar-16 5:54am
Comments
Richard Deeming 24-Mar-16 11:36am    
So you want us to tell you what's wrong with your code, without being able to see your code?

Come on! You've been here long enough to know that we can't see your screen, access your computer, or read your mind. If you don't show us the code, we can't help you.
s yu 24-Mar-16 11:40am    
Too many lines of code and also related to multiple server connection issues. Therefore, it is hard to post the code here. I want to get some general idea how to fix it. Thanks if you can provide some hints.
Andy Lanng 24-Mar-16 11:51am    
Guy goes to a Mechanic:
Guy: "My car won't start"
Mechanic: "Oh dear. Let's take a look under the hood, then."
Guy: "Oh you can't see it. It's very complicated. I just want a general idea of what could be wrong."
Mechanic: *Facepalm*

You see the issue? Maybe you could describe /exactly/ whats going wrong and we can help.

Some suggestions:
Is the form reloading? Without persistent state it will clear the form.
Is a control reloading within the form. This could be the same issue
s yu 24-Mar-16 15:43pm    
After changing the HTML controls to asp:controls + revising the code somehow, the problem reported was gone. Thanks for your reviewing.
Sergey Alexandrovich Kryukov 24-Mar-16 19:51pm    
It tells us that you simply don't understand how Web works. Most likely, your page is refreshed from an HTTP response, after a callback of otherwise. Apparently, you did not do anything to maintain the states of the values.
One of the solutions, a very universal one, making no assumption on what's up with the server side, would be Web Storage (sessionStorage, in your case).
—SA

1 solution

asp.net controls like textboxes etc re-populate themselves as part of their functionality, they maintain their own state, however html controls don't. If you want html controls to retain their values you have to code that in yourself, so give the boxes a "value" attribute that is the value of the submitted data. At it's most basic this could be something like

ASP.NET
<input type="text" name="mytext" value="<%=HttpUtility.HtmlEncode(Request.Form["mytext"]) %>" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900