c#
  • javascript
  • asp.net
  • 2012-02-08 70 views 0 likes 
    0

    我不確定爲什麼,但是我在PageLoad()函數內的ASP應用程序中發現了Javascript警報問題。它處理很好,但是當我嘗試另一個動作,我得到以下錯誤(這也只發生在IE瀏覽器和Visual Studio(在調試模式)):C#中的Javascript問題

    Line: 4056 
    Error: Unspecified error. 
    
        Response.Write("<script language='javascript'>alert(' You currently have an incomplete quote.\\n Here is your customers information: \\n First Name: " + _firstName + " \\n Last Name: " + _lastName+ " \\n Number Of Drivers: " + _driveList.Count().ToString() + " \\n Number Of Vehicles: " + _vehicleList.Count().ToString() + " \\n Date Of Quote: " + _pendingQuote.Date.ToString() + " ')</script>"); 
    
    +0

    是由Visual Studio或瀏覽器產生的錯誤?當你到達代碼中的那一點時,響應流是否關閉? – NotMe 2012-02-08 17:06:16

    +0

    你可以發佈你寫的C#代碼嗎? – 2012-02-08 17:13:29

    +1

    在這種情況下不要使用字符串連接。使用String.Format。 – 2012-02-08 17:14:34

    回答

    2

    你爲什麼不使用腳本管理

    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", string.Format("alert('{0}');",alertText), true); 
    

    ,並創建字符串生成警報文本像

    StringBuilder buildAlertString=new StringBuilder(); 
        buildAlertString.Append("You currently have an incomplete quote."); 
        buildAlertString.Append(Environment.NewLine); 
        buildAlertString.Append(string.Format("First Name:{0}",_firstName)); 
        ... 
        string alertText=buildAlertString.ToString() 
    

    這是更容易閱讀和格式。希望這可以幫助

    +0

    謝謝:),完美工作 – shenn 2012-02-08 17:33:17

    1

    嘗試:

    Response.Write("<script language='javascript'>alert(' You currently have an incomplete quote.\\n Here is your customers information: \\n First Name: " + "FNAME" + " \\n Last Name: " + "LNAME"+ " \\n Number Of Drivers: " + 6 + " \\n Number Of Vehicles: " + 6 + " \\n Date Of Quote: " + "DATE" + " ');</script>"); 
    

    然後嘗試:

    Response.Write("<script language='javascript'>alert(' You currently have an incomplete quote.| Here is your customers information: | First Name: " + "FNAME" + " | Last Name: " + "LNAME"+ " | Number Of Drivers: " + 6 + " | Number Of Vehicles: " + 6 + " | Date Of Quote: " + "DATE" + " ');</script>"); 
    
    相關問題