dcsimg
www.webdeveloper.com
Results 1 to 7 of 7

Thread: When I refresh my browser it calls ASP:Button, how to void it?

  1. #1
    Join Date
    Feb 2004
    Posts
    19

    When I refresh my browser it calls ASP:Button, how to void it?

    I have a problem with my asp.net in vb.net when I putsh the "refresh", "reload" button from my browser (Mozilla, Internet Explorer, Opera), my page thinks that I clicked again my ASP:Button, what I can do to avoid it, I already tryed inserting if page.isPostBack then ... but it didn't work

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    did you already click that button and the page fired a script, then you are clicking refresh? Its resending the post data, what you can do is when you click that button, have it do a response.redirect to another page then fire the script onload of that other page, that avoids post data. Either that or just use an html button and have the form action be the script on the other page.

  3. #3
    Join Date
    Feb 2004
    Posts
    19
    The problem about redirecting to another page is that when I trigger the button, I'm adding a row for each click so I really need to stay in courrent page, also redirecting to the same page will not work because I'm using Shared (Static) variables what are cleaned when not page.IsPostBack

  4. #4
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    could you pass the variables to the next page with a query string? Because hen you refresh a page and you are swapping out elements or changing elements, all the events the user performed must happen again, which is going to throw errors if a record no longer exists or something.

  5. #5
    Join Date
    Jun 2004
    Location
    Honolulu, Hawaii
    Posts
    13
    my page thinks that I clicked again my ASP:Button
    By default the ASP.BUTTON always causes a form to be submitted to the server when the user clicks them. Use the HTMLButton instead. If you define it like this:

    <button OnServerClick=" FancyBtn_Click" runat=server>

    You can still process the button click on the server.

    Also, using static (shared) variable isn't a good idea. If you need to maintain a varables state across post-backs use a ViewState to store the value in.

  6. #6
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    Originally posted by roteague
    Also, using static (shared) variable isn't a good idea. If you need to maintain a varables state across post-backs use a ViewState to store the value in.
    I would rather keep it in a hidden input and not use viewstate. But if you use a client side button it is still going to have to resend the page in order to execute a server side script. So the form action is going to come into play, but if it is a server side form the form action should be the page you are on so that would not be a problem.

    But I do not like keeping a lot of stuff on one page, when you can it is often good to split stuff up, to get rid of post data complications.

  7. #7
    Join Date
    Feb 2004
    Posts
    19
    Originally posted by roteague
    By default the ASP.BUTTON always causes a form to be submitted to the server when the user clicks them. Use the HTMLButton instead. If you define it like this:

    <button OnServerClick=" FancyBtn_Click" runat=server>

    You can still process the button click on the server.

    Also, using static (shared) variable isn't a good idea. If you need to maintain a varables state across post-backs use a ViewState to store the value in.
    I tried that too and didn't work because when I add ID="sss" and Runat="server" it now acts like an <ASP:Button

    Anyway what I did was just verify that I don't just have added it once, if it has been added then I bypassed the row.add() function.

    Thanks for your help guys

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles