2011-10-08 141 views
1

我是Jquery和javascript的新手。我在我的as.net项目中使用Jquery UI选项卡。我的标签内容是dynamic.so,我使用SQL Server来保存并检索它们。我有一个类来建立基于点击特殊按钮的标签。这是我的课:点击加载jquery标签内容

public class TabBuilder{ 
public string Build(int ServiceId) 
{ 

    string title = " <div class='demo'><div id='tabs' onclick='alert(yes)'><ul>\n"; 
    string content = ""; 

    DataTable select = new DataTable(); 
    ServicesBLL ser = new ServicesBLL(); 
    select = ser.FormsSelTabs(ServiceId); 

    int i = 1; 

    foreach (DataRow row in select.Rows) 
    { 

     title += createTitle(row["LinkName"].ToString(), i); 
     content += createContent(row["LinkHref"].ToString(), i); 
     i++; 
    } 
    title += "</ul>\n"; 
    content += "</div></div>"; 

    return title + content; 
} 

private string createTitle(string title, int i) 
{ 

    string htm = "<li><a id='tab{0}' href='#tabs-{1}'>{2}</a></li>\n"; 
    htm = string.Format(htm, i,i, title); 
    return htm; 
} 

private string createContent(string content, int i) 
{ 
    string htm = "<div id='tabs-{0}'><iframe dir='rtl' frameborder='0' height='600px' width='100%' src='{1}'></iframe></div>\n"; 
    htm = string.Format(htm, i, content); 
    return htm; 
}} 
在我的aspx页面

我有一个文本(LtrTabs)来显示标签和aspx.cs代码,我有这样的代码来构建标签:

protected void btnEntities_Click(object sender, EventArgs e) 
{ 
    ServiceID = 1; 
    TabBuilder tab = new TabBuilder(); 
    LtrTabs.Text = tab.Build(ServiceID); 
} 

我需要懒加载标签,但我不知道如何实现它。我看到了一些例子,但是没有一个使用数据库来加载内容。

+0

作为更一般的说明,你真的不应该在服务器端代码中输出HTML。尤其是_compiled_服务器端代码。如果你的平面设计师想要改变iframe的大小呢? – 2011-10-08 13:22:26

回答

1

我并没有通过服务器端代码筛选就知道肯定,但只要你有一个函数与标记输出标签,看起来像这样:

http://jqueryui.com/demos/tabs/#Ajax_mode

然后,这只是一个用有效资源填充hrefs的问题。在服务器端,只要它能够识别HTML内容的传入请求(无需发回制表符等等,只是内容),这就是您所需要的。

要回顾一下:

  1. 函数返回空选项卡中的HTML。或者,如果这不需要是动态的,只需将它写为HTML;没有必要用不必要的逻辑使事情复杂化。

  2. 函数返回标签的内容。

你怎么区分这两者真的取决于你。 POST/GET变量,不同的URL ......但是你的应用程序正在构建。