Disable auto check in asp:Checkbox when click browser back button

Emily-J 21 Reputation points
2021-12-03T07:07:54.573+00:00

Hi,

I’m a new in asp.net. I'm creating a web forms app.
I have page 1 that displays a list of employees in asp:Table, each row contains a checkbox.
When I tick the checkbox of a row and press delete button to delete the employee, the page 1 is redirected to page 2.
But when I press the back button of browser to go back to page 1, that row I mentioned above is deleted but the checkbox of the next row (now is the first row) is automatically checked.

I have tried to find out the reason, but unfortunately I got nothing. If anyone know my issue, let me know what I can do to fix it!

Thanks and best regards,
Emily

Developer technologies ASP.NET Other
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,096 Reputation points
    2021-12-09T03:20:48.633+00:00

    Hi @Emily-J ,

    That is: I used the site master for all of pages, when I fill out a form in the page A, then I go to page B and go back, the form is cleared.

    Solution:
    You could add jquery on your page to set autocomplete on the checkbox. The reason of that you don't success to work your operations is you can't get the id of the checkbox. When you put the checkbox in the ContentPlaceHolder, the id is changed. It will be 'ContentPlaceHolder1_XXX'.So, your operations don't work. You could use the type.
    Just like this:

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">  
        <script src="Scripts/jquery-3.6.0.min.js"></script>  
        <script>  
            $(function () {  
                $('input[type=checkbox]').attr("autocomplete", "off");  
            })  
        </script>  
    </asp:Content>  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Emily-J 21 Reputation points
    2021-12-06T01:59:44.03+00:00
    0 comments No comments

  2. Yijing Sun-MSFT 7,096 Reputation points
    2021-12-07T02:11:42.833+00:00

    Hi @Emily-J ,
    I think you could add "autocomplete="off"" on your master page's form or your checkbox.Just like this:

    <form id="form1" runat="server" autocomplete="off">  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Emily-J 21 Reputation points
    2021-12-08T10:15:47.147+00:00

    Hi @Yijing Sun-MSFT ,
    Thank for your reply!
    I have add autocomplete=false to the form of the site master. It works. But, I’m facing another issue. That is: I used the site master for all of pages, when I fill out a form in the page A, then I go to page B and go back, the form is cleared.
    I have tried to add autocomplete=false to the Checkbox: checkBox.Attributes.Add("autocomplete", "off"), but it’s not working as my expectation.

    Do you know what I can do to fix it?

    Thanks and best regards,
    Emily

    0 comments No comments

  4. Emily-J 21 Reputation points
    2021-12-17T08:47:02.097+00:00

    Hi @Yijing Sun-MSFT ,

    It’s works as my expectation. So many thanks for your help!

    Best regards,
    Emily

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.