ASP.NET wizard control navigates twice after changing ActiveStepIndex - c#

I have an application with a bunch of wizards. In one of the wizards when the user is on the last step some code runs in the code-behind to check the form's values so far. If there is an issue with one of the values, a yes/no pop-up gets displayed (user control). If the user clicks on yes, they get taken to the step with the incorrect values via changing ActiveStepIndex in the code-behind.
This works locally and on my build server, the step gets changed, navigation happens and all is well. But on my QA server another post-back is triggered immediately afterwards that navigates to the previous step again.
Through debugging I have found that the AJAX post-back is triggered from the _domReady function of MicrosoftAjax.js. Apparently it's supposed to check for browser navigation events or some such. In my case the state comparison that gets done in the _navigate function results in the second post-back happening because the two states are different. The new state is different from the old state, which gets set by the ScriptManager source.
function Sys$_Application$_navigate(entry) {
this._ensureHistory();
var state = this._deserializeState(entry);
if (this._uniqueId) {
var oldServerEntry = this._state.__s || '';
var newServerEntry = state.__s || '';
if (newServerEntry !== oldServerEntry) {
this._updateHiddenField(newServerEntry);
__doPostBack(this._uniqueId, newServerEntry);
this._state = state;
return;
}
}
this._setState(entry);
this._state = state;
this._raiseNavigate();
}
Any idea why the server states might be different in one environment but not the other? It happens in all browsers, by the way.

I turned out the warning pop-up was outside the wizard's update panel. After I moved it inside the update panel, the view states were in sync and no extra post-back was made.
I still don't understand why it worked fine locally, though.

Related

Data inside a LIst<String[]> dissappears (UWP)

the situation is the following:
On Page one i have a button that leads to page two and transports itself as an object to that site.
On page 2 i can set a few things that are stored in a List<string[]> that list is now moved by calling a method on Page one that sets the List on that page. and then i return to page one.
Everything is set and the data was received.
Now as soon as i try to access that data it gets null. I have no statement anywhere in the code that could set it to null. I only have to references:
1.
public void setMaterialData(List<string[]> data )
{
MaterialData = data;
}
and 2.
dataObject.materialdata = MaterialData;
and i already checked if the constructor is called again and overwrites it, but it doesn't. And strangely that happens with nothing else in my code so far.
Things that might be important:
I have the cache mode set to enabled,
I noticed that the constructor of the Window is called when i navigate away from page one to page two and i don't know why?(there is no reference to my list in there though)
Thank you in advance for your answer.
if you are not caching page then the newly navigated page is a new instance of the page and that maybe one possibility of getting field and property to Null
another possibility is resetting the variable as the page loads because every time the
page comes up to display it fires up page_loaded event if you are using that for initializing variable and other components than that may reset them to null
can you can check and confirm that if the navigated page is the same as the saved instance simply by checking (savedObj == this)

Postback of a dynamic create button not always executed

I have an ASP page with a table containing always different rows, dynamically loaded from a MSSQL DB. In each row of the table I have created a Button, called Details, that is dynamically created during the writing of the table. This Details button is added with the following code:
Button detailsButton = new Button();
detailsButton.Height = new Unit("18px");
detailsButton.Width = new Unit("65px");
detailsButton.Text = "Details";
detailsButton.ID = row.ItemArray[0].ToString();
detailsButton.PostBackUrl = "~\\DetailsPage.aspx?selectedSignalling=" + detailsButton.ID;
//detailsButton.Click += detailsAgencyButton_Click;
//detailsButton.OnClientClick = "return true;";
table1cell4.Controls.Add(detailsButton);
table1row.Cells.Add(table1cell4);
The intention is to redirect the client towards the Postback URL when one button is pressed on a row. The Postback URL is dynamically created for each button, associating to each of them the ID of the item that the user would choose to display the details.
While this works fine on the my development environment, that is running IIS 7.5, this is not always working on the production environment, that runs IIS 6.0 and that cannot be updated. On IIS 6.0, some clients does not notice any problem, while others are not able to display the details page, but, when clicking on the Details button, the postback URL is not loaded and instead there is only the reload of the current page.
I have tried to change many settings (set the detailsButton.Click, set the OnClientClick to "return true;"), but without luck. I have only noticed that adding the:
detailsButton.OnClientClick = "return true;";
instruction, the redirect does not work in IIS 7.5 too. So it seems to me that when OnClientClick returns something (true/false), the PostBack is not activated, while some of the clients probably does not return any OnClientClick and the PostBack is activated.
I solved my problem using javascript redirect associated to onClientClick event and returning false on the same event. This prevents the server to be invoked and the client redirects towards the new page without refreshing the old page.
detailsButton.OnClientClick = "windows.open(' new_page.aspx ', '_self'); return false;";

Viewstate history gets affected by activity on a different page

I have a current problem where on one page, the Viewstate info is disappearing if we open a different page and do a few postbacks there, ie:
Open ListPage, change form selected options and do postback
Press button that opens AddPage on new Tab
On AddPage, add several new entries doing several postbacks, close tab
Go back to ListPage try to refresh the grid
On ListPage, viewstate is empty
So if I have a property that is storing and getting it's value from viewstate, on step 5 is getting null from viewstate.
if (ViewState["Stuff"] == null)
return MyObject.Default;
else
return (MyObject)ViewState["Stuff"];
From my understanding viewstate history size is by default 9 ( <sessionPageState historySize="9" /> ) but I wasn't expecting this to be shared between different pages and don't want to change this value.
I can go around the properties stored by storing them in session with a Guid generated per page, but the form controls and anything that got it's value from the database needs to be re-setted.
Is there any way to make the viewstate history independent between tabs/windows? Or any idea how to go around it?
I'm using Telerik controls on each page if that helps.
Edit: this explanation helped me understand how exactly the viewstate info is stored in session and how sessionPageState configuration affects it.
Found out what was happening,
By default the Pages are storing the ViewState in Session, ie, using the System.Web.UI.SessionPageStatePersister. Knowing this, then the observed behaviour is normal. It only stores a certain amount of page states (postbacks) and for every postback, the older info get lost, no matter in which tab/page the postback is being made of, as long as it's in the same session.
I added this to my pages to tell it to store the ViewState in the page itself, in an hidden field. That was already what I assumed it was happening.
protected override PageStatePersister PageStatePersister
{
get
{
return new HiddenFieldPageStatePersister(this);
}
}

IsPostBack property of the page never gets false even after page refresh

I get stuck in a very unusual problem. I've a code written in C# which is simply checking IsPostBack property on the Page_Load. I know that IsPostBack remains false when page lands for the first time and bocme true only when any control post the form to the server (having runat=sever).
I also know that if we hit refresh, the IsPostBack property should change to false (since refresh is not a postback).
This is the sample code:
if (!IsPostBack)
{
// If I click on any control on the page, and then hit refresh,
// the code inside this block should execute, but this is not happening.
// After first postback, I tried refreshing the page for more than
// ten times, but always finds IsPostBack=true
// ...
}
else
{
// ...
}
I clicked on a server side button (a postback), then hit refresh. I assume it will go to the if block but no luck. No matter how many times i hit Refresh on browser, IsPostBack is always true. which is truly an unusual activity I've never seen before.
I would really appreciate any help. I need to know why this is happening, is this a browser related problem or something else? I used mozilla and chrome.
Every time I hit refresh, I get a warning on both browsers.
On chrome: Confirm form submission
The page that you're looking for used info that you entered, returning to that page might cause any action you took to be repeated.Do you want to continue?
On mozilla: Confirm
To display the page, firefox must send info that will repeat any action...
Thanks in advance for any kind help.
Praveen
Most browser will do a post of the same data if you refresh after posting.
This is the meaning of the dialogues you have seen (they are asking if you want to re-post - click yes/OK means a re-post).
In order to avoid the re-post, simply go to the address bar and press enter. That will cause a new request to be issues rather than a re-post.
Those dialogs that the browsers put up tell you that they are going to do a postback instead of just get'ting the page. And you can see in your code that the warnings are accurate - any handlers that were invoked on the original postback will get invoked a second time. This is one of the main problems with postbacks - they essentially break the refresh key. If you just want to load the page, you have to mouse up to the address bar and hit enter. This will load the page with IsPostback false.

jQuery Validate Plugin overwrite my select onChange postback

I'm creating this form (.net) where i have a select with a postback, that will trigger a action depending on which option i select. I'm trying to use the jQuery Validate Plugin (plugin website) to validate my form.
My problem is, when i validate the form, and my select is marked as invalid, the validation plugin overwrite it's onChange method to make it unmark when i change the value, the thing is that it's deleting my __dopostback from the onchange, making the form 'useless'.
Is there a way to the plugin validate my selects without deleting my postback action from the onchange?
I know this is an old post, but I had a similar situation and was able to resolve it like this. Just thought I'd post it just in case someone else found there way here. I'm using jQuery Validation Plugin 1.9.0:
$('#aspnetForm').validate({
errorLabelContainer: "#messageBox",
wrapper: "li"
});
$("input[id$='myButton']").click(function () {
SetRules();
if ($('#aspnetForm').valid()) {
// form passed validation
} else {
$('#aspnetForm').resetForm();
return false;
}
});
function SetRules(){
$("select[id$='myDropDown']").rules("remove");
$("select[id$='myDropDown']").rules("add", {required:true});
}
My validator is set up so errors display together in one designated div. When I click the button, the validation fires and displays all the elements in that div and marks the fields that are invalid, including the select (all choices are red), and when I change the selection my autopostback fires and the colors of the select change back to their old value (assuming the choice passed the validation).
I am pretty new at this plugin, so I can't explain it too well but my thought process was to try and get the form to validate and show the errors, and then reset the controls back to their original state while still keeping the error messages visible. I was expecting to lose the red error highlighting, but somehow that retained while also bringing back the select's postback.
Also, I do not know if setting the rules in this manner contributed to this working or not; I had to set them like this for various reasons, the biggest one due to needing the selector for .NET's automatically generated IDs.

Categories