0

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

2 Answers 2

1

You'll need to call a pagemethod from the jQuery, passing the data along with it.

A good example of this can be found here:

http://trentgardner.net/net/asp-net-webmethods-with-jquery-and-ajax/

Sign up to request clarification or add additional context in comments.

Comments

0

I was able to read the value of dataTextBox by the following line of code in Page_Load

 Dim testStr As String = Request.Form("draftData")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.