1

我正在 asp.net 中制作一个 Web 应用程序。我需要翻页效果,所以我使用了 turn.js(参考:http ://www.turnjs.com/ )。现在我需要在服务器端处理一些数据,即代码隐藏并将其发送到客户端。我从上面的网站(来自:https ://github.com/blasten/turn.js )下载了这个项目。但问题是我无法弄清楚如何将数据从代码隐藏发送到实际加载动态页面的 .aspx 页面中的 JavaScript。

function addPage(page, book) {
        //  First check if the page is already in the book
        if (!book.turn('hasPage', page)) {
            // Create an element for this page
            var element = $('<div />', {'class': 'page '+((page%2==0) ? 'odd' : 'even'), 'id': 'page-'+page}).html('<i class="loader"></i>');
            // If not then add the page
            book.turn('addPage', element, page);
            // Let's assum that the data is comming from the server and the request takes 1s.
            setTimeout(function(){
                    element.html('<div class="data">Data for page '+page+'</div>');
            }, 1000);
        }
    }

这是添加动态页面的 JavaScript 函数。如何在行中添加页面内容element.html('<div class="data">Data for page '+page+'</div>');

4

3 回答 3

0

in your aspx page element.html('<%=pageData%>')

in your code behind create a public string called pageData and then in your code (parhaps page Load event) put the string of data that you want into pageData

Or you can create a web service or just a simple ashx file, to respond with the required data and use ajax to get the next page data.

于 2012-04-11T15:09:14.283 回答
0

有几种方法可以按照您的要求进行操作。

  1. 在您的 javascript 函数中添加一个 asp:Literal 控件。在后面的代码中设置它的内容。

        setTimeout(function(){
                element.html('<div class="data">Data for page '+<asp:Literal runat="server" Id="litPageData"></asp:Literal>+'</div>');
        }, 1000);
    
  2. 添加一个隐藏字段,在后面的代码中设置它,然后在您的 Javascript 中访问该值。

    <asp:Hidden runat="server" id="hidPageData"></asp:Hidden>
    

    (我可能对这个语法有点偏离)

        setTimeout(function(){
                element.html('<div class="data">Data for page '+$('#<%= hidPageData.ClientId%>').val() +'</div>');
        }, 1000);
    
  3. Symeon 的解决方案,已经发布。

于 2012-04-11T15:17:31.883 回答
0

在您的代码隐藏中,例如 code.cs 声明一个变量:

String strDummyValues = "Dummy value";

在您的 ASPX 页面中:

使用<%=strDummyValues%>手段

element.html('<div class="data">Data for page '+<%=strDummyValues%>+'</div>');
于 2012-04-11T15:50:51.520 回答