I'm making a webpage in ASP.net, combined with VB.net. The current page I'm working on, is some sort of 'Quiz' webpage. The user has to fill in 40+ radiobuttons, depending on his personality and such.
Though throughout testing I've realized the webpage will occasionally reload, forcing every checked radiobutton to go back to unchecked. This will happen at seemingly random moments, sometimes not at all, sometimes 2 times in a row. This is especially annoying since there are so many radiobuttons to be checked, forcing the user to start over.
Does anybody have any idea why this could happen? Any help would be much appreciated.
if(!Page.IsPostback)
{
//.. your code goes here
}
Related
I have a really weird issue that affects only a few users...
I have an ASP.NET site with an AJAX Control Toolkit combobox. When these users try typing in the combobox, the first character they type is often not recognized. They often need to hit the key twice to get it to register.
At first I thought this was an issue with their keyboards, so I had one of the users try on my keyboard. She was able to duplicate the behavior. However, when I try, it's usually fine. (I've only been able to successfully duplicate this once)
Is this a keyboard issue, or is there something else I can look at? The standard browser here is IE9.
EDIT
I've been able to reliably duplicate the "problem"...
When a user engages the dropdownlist and then starts typing, the first keystroke sets focus back in the textbox. This creates the illusion that the first keystroke didn't register. I hate to say it, but this appears to be by design. Any thoughts?
I'm trying to describe it in as few steps as possible:
I have Page1.aspx with lot of controls, and Preview and Save button among those. I also have Page2.aspx that is the redirection target of a Preview Button click.
Since I need all the controls selections from Page1 to draw a preview on Page2 the redirection is done with setting Preview's PostBackUrl.
I also must have preview shown on a new tab or window so I used onClientClick="aspnetForm.target='_blank'" for Preview button definition.
Save button-click callback, after storing data to a database does redirection to some Page0.aspx (initial list of reports - the subject of the code)
Preview button works fine - a preview renders in a new tab, but when I go to the old tab and click on Save, I see from debugger, that firstly Page2.aspx(?) and secondly Page1.aspx are loaded. Then all the data is stored in the db, but though Page0 redirection is executed Page1.aspx stays loaded in the browser.
I have no idea what processes are behind this. Could one who knows give me an insight? Or if you consider my approach impossible to implement give some idea how to do the same?
If it's of importance, everything on the Page1 is located in an update panel.
Thank you very much for replying
In ASP.NET there are basically zero (0) circumstances in which you will ever send form data from one page to another. Although what exactly you are trying to accomplish is vague, you can consider some of the following:
Isolate unique operations/systems to a single page. If you have something like a User Profile, don't have three different aspx pages; just use a single page for the user or admin to manage that data / functions. Postback events are your friend.
Understand the difference between ViewState and traditional form data. I'm guessing that if you're trying to post form data from one page to another, you probably don't understand the point of ViewState. Using a single page to maintain temporary data that the user is currently working with is a great use for ViewState. If you want the data to appear on another page then you need to consider the data from the previous page as final and thus should be saved to a database or some other medium.
These are just some general guidelines because there is no exact answer to your problem without saying something generic like "You're doing it wrong." I would recommend starting by never again trying to post form data from one aspx page to another.
I am using asp.net 3.5 (codebehind c#). My users are running IE 7 or 8. I have a data entry page with several TextBoxes.
When I want to clear the all the TextBoxes, I do a sever.transfer back to the same page.
Maybe 99% of the time, this clears the TextBoxes. Every so often it does not.
I know that a roundtrip to the server has happened because:
The dropdown lists and radiobuttonlists on the page get reset, and
DB processing happened as shown by a record having been saved to the
DB.
The inconsistency is confusing me.
What could be causing the TextBoxes to persist data in this way and how can I prevent it from ever happening?
It is resulting in users saving the same data twice.
I don't think this would have anything to do with it, but there are also various js functions on the page for validation, capitalizing the first letter of an input, etc
As this MSDN article describes the Server.Transfer method, this is probably not the right way to empty the TextBoxes. The method explicitly keeps all state information.
A better approach is described within this answer:
foreach (var item in Page.Controls)
{
if (item is TextBox)
{
((TextBox)item).Text = "";
}
}
You will keep the roundtrips to just one, and you could keep all other user inputs as they were, if you like.
I'm really new to asp.net and have a couple of issues I'm trying to get fixed. I have some programming experience, but it is not asp.net. However, I've been able to follow the code enough to make other changes in the code to fix other issues.
The first is this:
I'm working with a form that has a calculate amount method that gets called when the user inputs a value in an amount text box. The same method gets called when the next control, number of payments, has a value.
So in the two controls:
onTextChanged="ctrlName_textChanged"
Then in the code behind, the textchanged method does:
calculateAmount();
The problem is after the amount is calculated and returns, the focus seems to get reset and the user has to tab all the way back through the form to the place they were.
The textboxes in question are in a panel that starts out hidden and is made visible conditionally.
My apologies if I have not used the proper .net terminology.
It looks like the same issue may be causing my second problem. When the user types in an amount and then tabs and quickly adds the number of payments, you can see the amount get calculated correctly and very shortly displays the proper total in the total amount text box. However, even though it shows for that short time, the tab order again gets reset as well as the total amount value.
I've looked at different methods to try and fix the focus issue.
In the textchanged method, I tried using something like:
Session["myval"] = "someval";
Then tried to check against that in Page_Load with something like:
if(Session["myval"] != null) {
this.NextControl_Name.Focus();
}
but it didn't ever work correctly.
I also tried to set a cookie in that same textchanged method using something like this:
Response.Cookies["myval"].Value = "somevalue";
Then tried to check that in Page_Load using something like the previous if block above but using Request.Cookies["myval"] as the source.
Is there a good reference with some really clear code samples I can look at for this type of implementation?
Thank you in advance,
C.
Sounds like you have a postback problem...
Remember that the web is stateless. This means that when you have a web page rendered out in .NET and you attach an event that executes serverside code... it does an HTTP POST back to the server which is effectively a new page request. The Page_Load method will fire again as well as your bound event. So your onTextChanged event is firing a new request back to the server. This is why you see the focus reset and why when you tab quickly, the value seems to disappear magically.
You can do one of several things, you can implement the UpdatePanel in the AjaxControlToolkit
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/
you can use PageMethods and do your validation with javascript and jQuery (or other js library)
see page method info http://www.geekzilla.co.uk/View30F417D1-8E5B-4C03-99EB-379F167F26B6.htm
Hope this helps
All over my application, buttons, link buttons and image buttons seem to become disabled. A few refreshes of the page, or a reload, or sometimes it requires a restart of my browser (This occurs in all browser) will re-enable the button. I haven't got a clue how this is happening and it is driving me, and my clients nuts. I am assuming it must be something to do with the page lifecycle but can't understand why the issue is intermittent.
Has anyone come across this before?
Look at all the intial states of your buttons in the .aspx page. See if it's all consistent as far as their Visible and Enabled properties.
Then identify any code in your code-behinds or javascript that would modify those properties. (I always have a Sub called 'SetFormAttributes' in my maintenance pages)
Look for things that might inconsistently cause postbacks that you might not be seeing.
The key to finding this is to understanding everything that is or COULD be going on in that page.