本文介绍了在VB .Net 代码后面读取JQurey.ajax URL 调用数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望读取 .aspx 页面中文本框的值并每隔几秒保存一次.

I wish to read the value of a text box in a .aspx page and save it every so many seconds.

我在以下位置找到了以下代码:如何实施自动保存"或保存草稿"ASP.NET 中的功能?

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');
            }
        });
    }

假设 dataTextBox 是在 .aspx 页面中定义的文本框.我在 VB .Net 后面有代码.但是我不知道如何在后面的代码中获取文本框文本字段的值.我想我是通过线draftData传递它: $("#<%=dataTextBox.ClientID %>").val() 到 SaveDraft.aspx.

Let 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.

在 SaveDraft.aspx.vb 中,我有:

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

推荐答案

我能够通过 Page_Load 中的以下代码行读取 dataTextBox 的值

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")

这篇关于在VB .Net 代码后面读取JQurey.ajax URL 调用数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:07