Submit changes from a form back to a database
-
Hello all, I have a form that allows users to enter data and a button users can click to send data to the database. To ensure that data are sent to the database if and only if the form is modified, is it enough to use the statement if(!page.ispostback) in the button Onclick event in the codebehind page to check if the page is being sent to the server? Aside from the code to connect to a database then update or insert data, is there something else I would have to do? Thanks in advance.
-
Hello all, I have a form that allows users to enter data and a button users can click to send data to the database. To ensure that data are sent to the database if and only if the form is modified, is it enough to use the statement if(!page.ispostback) in the button Onclick event in the codebehind page to check if the page is being sent to the server? Aside from the code to connect to a database then update or insert data, is there something else I would have to do? Thanks in advance.
I hope this helps: A page will be a postback if a user submits something (either by click or any other mechanism) and you use the same page C# / VB after what triggered the submision. Therefore, using a button on a form will cause it to be a postback, and the if (!IsPostback... will enter into effect, preventing you to get to the desired code. If you want to prevent a user from clicking the same button or triggering the same mechanism, at the end of your code you can disable the button with something as Button1.Enabled = false; which is the most common I've seen. That way, the user won't be able to make a second change with that particular button.
-
Hello all, I have a form that allows users to enter data and a button users can click to send data to the database. To ensure that data are sent to the database if and only if the form is modified, is it enough to use the statement if(!page.ispostback) in the button Onclick event in the codebehind page to check if the page is being sent to the server? Aside from the code to connect to a database then update or insert data, is there something else I would have to do? Thanks in advance.
No, that will not help. In fact, it will prevent you from submiting the data on the first attempt if it is enclosed by the if "(!IsPostBack".