I wish to read the value of a text box in a .aspx page and save it every so many seconds.
I have found the following code at: How to implement an "Auto Save" or "Save Draft" feature in ASP.NET?
I modified it for my purposes a little bit:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
window.setInterval(saveDraft, 5000);
});
function saveDraft() {
$.ajax({
type: "POST",
url: "SaveDraft.aspx",
data: ({
draftData: $("#<%=dataTextBox.ClientID %>").val()
}),
success: function(response) {
alert('saved draft');
}
});
}
</script>
Let's say dataTextBox is a textbox defined in the .aspx page. I have the code behind in VB .Net . But I do not know how I can get the value of the text box text field in the code behind. I suppose I am passing it through the line
draftData: $("#<%=dataTextBox.ClientID %>").val()
to SaveDraft.aspx.
In SaveDraft.aspx.vb I have:
Public Partial Class SaveDraft
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' What should go here to read dataTextBox.text?
End Sub
End Class