简体   繁体   English

为什么用代码编写的锚标记的href背后不接受“ aspx”

[英]Why is the href of anchor tag written in code behind not accepting 'aspx'

I have a calender control and on selecting a respective date, I need to display Today's Due and Over due as two section in an accordion. 我有一个压光机控件,在选择一个相应的日期时,我需要将“今日到期”和“到期”显示为手风琴中的两个部分。 I have written the div for accordion in code behind and set style.css to give the look of Accordion. 我已经在后面的代码中为手风琴编写了div,并设置了style.css来赋予手风琴外观。 The data from code behind is converted into json and displayed. 来自后面代码的数据将转换为json并显示。 The code behind is as follows: 后面的代码如下:

[WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string CalenderBinderAccordian()
        {
            try
            {
                //Code to fetch productGroup is not shown
                foreach (var p in productGroup)
                {
                    var todoCount = 1;
                    string todoString = "";
                    int uniqueID = Guid.NewGuid().GetHashCode();
                    todoString = "<div class='accordion vertical'><section id='" + uniqueID + "' style='overflow-y: scroll;'> <h2><a href=#" + uniqueID + "><b>Due Today</b></a></h2>";    
                    foreach (var t in p.todo)
                    {
                        var tempAmt = String.Empty;
                        if ((t.Amount == null) || t.Amount == String.Empty)
                            tempAmt = "0";
                        else
                            tempAmt = Convert.ToDecimal(t.Amount.ToString()).ToString();                          
                        todoString += "<p><div style='padding:5px 0px; border-bottom:dashed 1px #dddddd;'><b>" + todoCount.ToString() + "</b>. " + t.ProductName + "<span style='text-align:right; padding-right:5px;'> $" + tempAmt + "</span><a href='www.google.com' target='_blank' style='text-decoration:none;'><b>Pay Now</b></a></div></p>";
                        todoCount++;
                    }
                    todoString += "</section>";   

                    var overDue = temps.Select(x => new { x.DueDate }).Distinct().ToList();
                    int overDueCount = 0;
                    uniqueID = Guid.NewGuid().GetHashCode();
                    todoString += "<section id='" + uniqueID + "'> <h2><a href=#" + uniqueID + "><b>Over Due</b></a></h2>";
                    int todoCount1 = 1;
                    for (int i = 0; i < overDue.Count(); i++)
                    {

                        if ((Convert.ToDateTime(overDue[i].DueDate) - Convert.ToDateTime(p.dates)).Days < 0)
                        {
                            overDueCount++;

                            var overDueList = temps.FindAll(x => x.DueDate.Equals(overDue[i].DueDate)).ToList();
                            foreach (var t in overDueList)
                            {
                                var tempAmt = String.Empty;
                                if ((t.Amount == null) || t.Amount == String.Empty)
                                    tempAmt = "0";
                                else
                                    tempAmt = Convert.ToDecimal(t.Amount.ToString()).ToString();
      //Error occurs when the href is given as aspx                                                           
                                todoString += "<p><div style='padding:5px 0px; border-bottom:dashed 1px #dddddd;'><b>" + todoCount1.ToString() + "</b>. " + t.ProductName + "<span style='text-align:right; padding-right:5px;'> $" + tempAmt + "</span><a href='PaymentDetails.aspx' target='_blank' style='text-decoration:none;'><b>Pay Now</b></a></div></p>";
                                todoCount++;
                                todoCount1++;
                            }

                        }
                    }

                    todoString = todoString + "</section></div>\",\"count\":\"" + todoCount + "\"},";
                    jsonString = jsonString + String.Format("{{\"{0}\" : \"{1}\",\"{2}\" : \"{3}", "dates", p.dates, "todo", todoString);

                    if (overDueCount.Equals(0))
                    {
                        jsonString = jsonString.Replace("</section><section id='" + uniqueID + "'> <h2><a href=#" + uniqueID + "><b>Over Due</b></a></h2></section>", "</section>");
                    }  

                }
                jsonString = jsonString.TrimEnd(',');
                jsonString = '[' + jsonString + ']';
               string data= jsonString; JavaScriptSerializer().Serialize(productGroup);
                return data;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

//How to data is converted to Json var tododate = []; //如何将数据转换为Json var tododate = [];

$(window).bind('loaded', function () {
    $.ajax({
        type: "POST",
        url: "ChartBinder.asmx/CalenderBinderAccordian",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {        
            tododate = JSON.parse(msg.d);

        },
        error: function (msg) {
            alert("error");
        }
    });   
});

Kindly note when the href is given as www.google.com the functionality works well but when it is given as PaymentGateway.aspx It does not display date in accordion format rather shows error alert. 请注意,当href设为www.google.com时,该功能运行良好,但当其值为PaymentGateway.aspx时,它不会以手风琴格式显示日期,而是会显示错误警报。

Using Firebug, Noticed the following Error: Error during serialization or deserialization using the JSON JavaScriptSerializer. 使用Firebug,注意到以下错误:使用JSON JavaScriptSerializer进行序列化或反序列化时出错。 The length of the string exceeds the value set on the maxJsonLength property Solution: Tried changing the configuration : 字符串的长度超过了在maxJsonLength属性上设置的值解决方案:尝试更改配置:

<configuration> 
<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="50000000"/>
  </webServices>
</scripting>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM