我如何在没有ClientScript的情况下重写此代码. [英] How do I rewrite this code without ClientScript.

查看:75
本文介绍了我如何在没有ClientScript的情况下重写此代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用表单标签.或scriptManager只是jquery,ajax,c#html和css.

I am not using a form tag. or scriptManager just jquery, ajax, c# html and css.

List<spGetChaptersResult> chaps = BDC.DataContext.spGetChapters(bookID).ToList();
List<string> ChapsString = new List<string>();
foreach (spGetChaptersResult chptr in chaps)
{
   ChapsString.Add(chptr.PageNumber.ToString() + "," + chptr.ChapterTitle);
}
string[] SortedChapterPages = ChapsString.ToArray();
Array.Sort(SortedChapterPages, new Common.NaturalComparer());
foreach (string scp in SortedChapterPages)
{
   string outp = scp.Replace("'", "");
   //HOW DO I REWRITE THIS PEACE OF CODE. TO GET THE SAME OUTCOME.
   <big>ClientScript.RegisterArrayDeclaration("chaptsAndPages", "'" + outp + "'");</big>
}

推荐答案

您希望chaptsAndPages javascript变量可在客户端(浏览器)访问.
因此,如果您依赖C#代码生成javascript变量,则没有其他直接方法.

-您可以在Cookie中注册该值(不推荐)
-您可以在需要时进行AJAX调用以获取数组.
You want chaptsAndPages javascript variable to be accessible in the client side(browser).

So if you have dependency on the C# code to generate the javascript variable there is no other direct way.

- You can register the value in cookies(not recommended)
- You can make an AJAX call to get the Array when you need it.


问题已解决.

problem fixed.

[WebMethod(true)]
       public static string GetContentsMenu(int BookID)
       {
           var BDC = new BookDC();
           var fb = BDC.GetBook(BookID);
           var sb = new StringBuilder();
           List<spgetchaptersresult> chaps = BDC.DataContext.spGetChapters(BookID).ToList();
           List<string> ChapsString = new List<string>();
          foreach (spGetChaptersResult chptr in chaps)
          {
            ChapsString.Add(chptr.PageNumber.ToString() + " " + " " + chptr.ChapterTitle);
           }
           string[] SortedChapterPages = ChapsString.ToArray();
           Array.Sort(SortedChapterPages, new Common.NaturalComparer());
           sb.Append("<table>");
           foreach (string scp in SortedChapterPages)
           {
              string outp = scp.Replace("'", "");
              sb.AppendLine("<tr><td>");
              sb.AppendLine("<a href="#" id="pgNum">");
              sb.AppendLine(" ");
              sb.AppendLine(outp);
              sb.AppendLine(" ");
              sb.AppendLine("</a>");
              sb.AppendLine("</td></tr>");
           }
           sb.AppendLine("");
           string cpret = sb.ToString();
           return cpret;
       }


这篇关于我如何在没有ClientScript的情况下重写此代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆