ASP.NET Wizard Back Button won't work - asp.net

I have a ASP.NET Wizard running my checkout process of my shopping cart. I just added a Paypal Express checkout link to my 2nd step. The Paypal process takes the user away from the page and then redirects them back to my wizard when they're done. I'm parsing an HTTP parameter with Request.QueryString when the user comes back from Paypal to set the wizard to step 3. This loads just fine, but when I click on the Back button (of the wizard), it does a postback but stays on step 3. Can anyone think of a reason for this? The link it's referencing still has the HTTP parameters, but I'm checking for a postback prior to programmatically setting the wizard step based on the parameter. Does anyone have any experience with this?

Well, I'm not sure why it was doing it, but overriding the blackbox PreviousButtonClick event on the wizard with the following code fixed it. It seems to me like this should be the behavior the button was implementing anyway, but it wasn't. Weird.
Protected Sub wizSubmitOrder_PreviousButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizSubmitOrder.PreviousButtonClick
Dim previousStepIndex As Integer = wizSubmitOrder.ActiveStepIndex - 1
wizSubmitOrder.MoveTo(wizSubmitOrder.WizardSteps(previousStepIndex))
End Sub

Related

Asp.net disable action on Post Back page load

I've looked around and didn't find anuthing similar, what I'm looking for is a way to disable or stop whatever action that make the page post back on the page_load method according to some validation
example:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
'Validate here and stop the action
End If
End Sub
I've already tried to end the request but in this way I can't tell the user whats going on
If the page fails validation, then the whole idea that no post back WILL occur! So you as a general rule don't check in the post back for a validation that supposed to not allow the post back!!!
If validation and the validators are working correctly, then no post back can and should occur. Now if you want code behind to do some extra logic and processing and some extra testing?
The of course you allow the post back, and thus now in that button event code stub, or say dropdown list or whatever event code stub is being triggered? It is in THAT code that you can add additional validation.
So you might have a VERY nice regex validator that requires the user MUST enter a legal formatted email address. They then hit ok, and say you then run some code to check if the email is on-file, and at that point your code behind can:
Display a message on the screen, or even trigger a toast message (client side). Note that you CAN trigger nice toast message or client side script if that is the VERY last thing your code behind does, and this works rather well.
So yes, one can and will often have a mix between some validators on the page, and THEN some additional code "behind" that does and will run as a result of the post back having been allowed.
But, if validators (client side) are working, then you not have any post back to run, and thus you can't check anything at all anyway. If the validators are working correct, then no post back should occur at all.
However, as noted, if you need to write some additional logic for that button or control event? Then you let the post back occur, run that additonal logic, and display a message, or toast message or do whatever based on that input, and then the page will rendered again.

timer.tick killing my .net page

I have a simple timer method in vb, that currently does nothing, it just ticks. Once it does however, all my other code on the page stops working.
as an example, I have image buttons on my page that add controls to a static place holder.
btnCreate.Text = "Create"
btnCreate.ID = "btnCreateSpecialNotes"
AddHandler btnCreate.Click, AddressOf btnCreateSpecialNotes_Click
plhCreateSpecialNotes.Controls.Add(btnCreate)
so without the timer.tick method, that (along with other code not included) would fire off as expected and do what I want, but when the timer.tick happens, everything sort of freezes and nothing works.
My timer is set up as follows
<asp:Timer ID="specialNotesTimer" runat="server" Interval="2000" ontick="specialNotesTimer_Tick"></asp: Timer>
and in the code behind...
Protected Sub specialNotesTimer_Tick(Byval sender as object, Byval e as eventArgs) Handles specialNotesTimer.Tick
'Do things to the page
End Sub
DISCLAIMER: I have never used the System.Web.UI.Timer class.
I think there might be some confusion between client side javascript code and server side C# code.
After reading MSDN, it seems that the Timer control would initiate a full postback every 2000 milliseconds (2 seconds because you say so above). This can only be done in javascript and there needs to be a server side event handler that will perform some task on the server (you call it specialNotesTimer_Tick).
Now, if this task takes longer than 2 seconds to execute, I would assume that you will never see any information on the web page because it would constantly be postbacking (posting back?) and refreshing the screen.
Suggestions:
Reconsider your approach for using a timer
Increase the timer interval
Add an UpdatePanel so the processing happens asynchronously, thus avoiding the screen refresh
Hope this helps.
I think the main problem I had here was the flow of my html wasn't ending. I restarted my page from scratch slowly, and though I used virtually the identical code, I just triple checked all my close tags and what not in html, and that seemed to solve the problem itself.
I'm sorry there isn't a more in depth answer, but I still don't understand why my old code here wasn't working, but re-doing my page from square one worked for me.

debuggin in aspx

I am trying to debug some code in my code behind files for as aspx page. I have debug set to true both in the page and in my web.config.
Can someone tell me why a) the breakpoint never fires even though the dropdown gets filled and b) why when i uncomment the msgbox it never fires and the dropdown does NOT fill.
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack Then
ddlCity.Items.Clear()
Dim context As New enerteckEntities()
'Dim query = context.DistinctCityFromZiptax(Convert.ToInt16(ddlState.SelectedValue))
Dim query = From c In context.ziptaxes Where c.StateID = ddlState.SelectedValue Order By c.City Select c.City, c.ZipTaxId
'MsgBox(query.Distinct().ToList())
ddlCity.DataSource = query.Distinct().ToList()
ddlCity.DataValueField = "ziptaxid"
ddlCity.DataTextField = "City"
ddlCity.DataBind()
End If
End Sub
Well based on your code, you will only execute this after a PostBack and not on initial Page Load.
MsgBox will never show up because this is not a WinForms application! You cannot use that in a web.application. If you want you can use Response.Write() or just add a dummy Label to your page and set the text property temporarily. It is the same effect.
The easiest would be to just debug it. Make sure your breakpoints are full Red dots, and you must be in Debug mode. If you are trying to debug from IIS then you must attach to process. If you are using IIS7 (I am assuming you are) then you must go to:
Debug Menu > Attach to Process > Find the process named "w3wp.exe" and double click on it.
You are now attached.
If your breakpoints are not full red dots after starting debug, then your compiled code and your debug files do not match. Do a Rebuild as opposed to a Build. Beyond that you might be having a funky problem, you can try deleting your obj and bin folders (make sure to save any third party dlls first).
To hit a break point visual studio has to attach to the process hosting the aspx page.
This is typically done in a Web Application Project by pressing the F5 key or clicking on the "Debug" menu and clicking "Start Debugging".

How to wait three seconds then turn to another webpage

I'm new to web development, and I'm currently using ASP.net. I wonder what would I need to do to let the browser wait for 3 seconds so my users can read the text "Customer Successfully Added" before turning to another page? I have attached my code as follows.
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim db As New DatabaseClass
db.addProfile(txtLN.Text, txtFN.Text, txtUsername.Text, txtPassword.Text, txtAddress.Text, txtZip.Text, txtPhone.Text, txtEmail.Text)
lblMessage.Text = "Customer Successfully Added"
End Sub
In addition, I'm not sure how to utilize MSDN. For me, its information overload, I'm wondering how to go about finding the solution on MSDN so i would be able to solve my problems in the future. Thank you!
You can't do it in the code behind of the page because of how asp.net works - the label text would not update until after the timeout occurred if you did it in the code-behind.
The server-side processing spits all the html back to the browser only after it has completely processed any server-side code unless you're using Ajax. Since you're new, I won't even bother going into how to do it with Ajax as there is a MUCH simpler option for accomplishing what you want.
A simple method to accomplish what you're looking for would be to have a simple HTML page that just has a message that says "Customer successfully added" and use javascript (client-side code) to pause and then redirect using the Javascript "SetTimeout" function.
There's an example here: http://www.bloggingdeveloper.com/post/JavaScript-Url-Redirect-with-Delay.aspx
The logic flow wshould work like this:
The original page should add the record (in code-behind) then redirect to this simple html page (in code-behind). The html page should have the "Customer Added" message and use the SetTimeout and Redirect to go to whatever page you want the user to see after viewing the message.
For stuff like this you need the code to run client side rather than on the server. The easiest way to do this is to return some javascript with your page (in the .aspx part rather than the code behind)
Take a look here for an idea of what to do :)
The page is displayed for a few seconds and then the javascript triggers a redirect to a url of your choosing. Just add something like this into your html.
You can emit javascript to redirect to the other page, using the setTimeout function.
This is best accomplished using the ScriptManager to register any javascript on the page.

Page_Load not being called on re-navigation

I am having a strange problem. Here is the scenario
Here are my files:
Project1.aspx
Project2.aspx
They are set up the exact same, including their Page_Load functions:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
setPrevIndex(-1)
...
End If
End Sub
They are both set up this way.
Here is where I am running into a problem. When I navigate to either of these pages, i need to make sure that prevIndex is set to -1 (via the function).
For Project1.aspx when I navigate
to the page, the Page_Load fires.
For Project1.aspx when I refresh the page, the Page_Load fires.
For Project1.aspx when I press "Go" in my browsers navigation bar, traveling back to the current page, the Page_Load fires.
For Project2.aspx when I navigate
to the page, the Page_Load fires.
For Project2.aspx when I refresh
the page, the Page_Load fires.
For Project2.aspx when I press
"Go" in my browsers navigation bar,
traveling back to the current page,
the Page_Load doesn't fire at all! The function isn't even
called.
Any ideas why??? What would cause this?
Please ask for clarification.
Update:
When I press "Go" in the URL pointing to the same URL, it seems like the masterpage is the only thing that re-loads, but the Load_Page event doesn't even fire...
Any other suggestions?
Thanks,
E
Try disabling output cache and see if the problem still occurs:
<system.web>
<caching>
<outputCache enableOutputCache="false"/>
</caching>
<system.web>
Use LiveHTTPHeaders or Fiddler to make sure the page is actually being requested the same way each time. This may be an issue with caching.
Load up your website locally and go to http://yourwebsite/trace.axd
This shows a server trace for each page, along with the server status. It also shows the complete page lifecycle with timings.
Clear the current trace and then repeat your 3 visits and reloads each to Project1.aspx and Project2.aspx
What does trace.axd show now? You should have 6 entries, each with the status code of 200 and the verb GET.
If you have fewer then your problem is caching of some sort.
If you have 6 then check the details for the last one - what does is show for the page event lifecycle? It will also show the complete WebForm control hierarchy, so if this related to the master page you will be able to tell.
Try Setting the previndex to -1 in Page Init Event. I am not sure why this is happening though.
Various cache-related things can cause the request not to be made, in particular when you merely press the "go" button, so you should check your cache-headers.
If caching is the issue, you can do something like:
//ask browser to revalidate:
context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
//and hint that the page is outdated anyhow...
context.Response.Cache.SetMaxAge(TimeSpan.Zero);
Which should convince a browser to really get a new version every pageview. You could, for instance, set these variables in the Page_Load itself ;-). If you're not using https, then the following are risk-free too:
//prevents plugin based file-open in IE+https, otherwise fine:
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetNoStore();
I'll bet this solves it - and if not, I second Jeremy Steins suggestion that you use fiddler to verify that the request is really being made at all (and since you're a web-dev, get fiddler in any case, it's a handy tool to have available, and works for all browsers!).
Finally - can you tell whether any other code on the page runs when you click go? (i.e. is the entire page not running, or just Page_Load - the latter would suggest an event wire up error, which would be odd considering your load handler does sometimes fire).
It sounds like your page is cached. This would cause the Page_Load not to fire. Check that you have not set that anywhere.
Have you tried publishing the application to a different machine? It could be IIS doing something so try and eliminate that first. Assuming that your code is identical in both na only the page names differ (do a diff on the aspx and .cs files to verify) then move your application to a different server and re-test.
If it is still occurring the it really must be your browser doing something probably with respect to caching.
Try to recreate the scenario with stripped down functions on your server. If the problem persists, try to use some cache-countering methods. If not, that means it has to be your code.
If you have this (or similar) at the top of your page (or master page) this will cause it:
<%# OutputCache Duration="3600" VaryByParam="none" %>

Resources