开发者

How to wait three seconds then turn to another webpage

开发者 https://www.devze.com 2023-02-20 10:37 出处:网络
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\" befo

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 y开发者_Go百科ou!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消