Reza.Hoque
Reza.Hoque

Reputation: 2750

Data inserts automatically when I refresh the page ?

I have 2 textboxs and a button.

The target is to save textbox data on the button click and empty the textbox so that it gets ready for the next entry.

The problem is even though the textbox looks empty after the button click. If I refresh the page, the last inserted value automatically inserts into the database.

page code:

<script type="text/javascript">
$(document).ready(function () {
    $("#Time").val("");
    $("#Title").val("");
});

</script>
<%Html.EnableClientValidation(); %>
<% using (Html.BeginForm())
{ %>
<div id="fullform">
<h2>Enter the program list</h2>
<div id="CreateData">
    <div>
        <%:Html.LabelFor(m=>m.Year) %>
    </div>
    <div>
        <%:Html.TextBoxFor(m=>m.Year) %>
    </div>
    <div>
        <table>
            <tr>
                <td><%:Html.LabelFor(m=>m.Time) %></td>
                <td><%:Html.LabelFor(m=>m.Title) %></td>
                <td></td>
            </tr>
            <tr>
                <td><%:Html.TextBoxFor(m => m.Time)%></td>
                <td><%:Html.TextBoxFor(m=>m.Title) %></td>
                <td><input type="image" value="Register"     src="../../Content/images/btnAdd.png"/></td>
            </tr>
        </table>
    </div>

What am I doing wrong??

Upvotes: 1

Views: 288

Answers (1)

ipr101
ipr101

Reputation: 24236

I suspect your problem might be caused by the page refresh itself, which could re-posting your previous data to the server.

After your page has posted the data could you redirect to a different page?

There's further info on data reposts after a page refresh in a Wikipedia article here - http://en.wikipedia.org/wiki/Post/Redirect/Get

Upvotes: 2

Related Questions