Analytics

顯示具有 AJAX 標籤的文章。 顯示所有文章
顯示具有 AJAX 標籤的文章。 顯示所有文章

2016年11月3日 星期四

[UpdateProgress]解決 Javascript觸發時UpdateProgress未顯示( UpdateProgress is not working when Javascript is triggered)


問題
Javascript觸發時UpdateProgress未顯示



解決方法
.aspx
 <style type="text/css">
    .transparent
    {
        zoom: 1;
        filter: alpha(opacity=50);
        opacity: 0.5;
        width: 100%;
        background-color: Gray;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 9999999;
        text-align: center;
        margin-top: 0px;
    }
    </style>

    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
        <ProgressTemplate>
            <div id="divMask" class="transparent">
                <table width="100%">
                    <tr>
                        <td style="height: 300px">
                            <h2>
                                L O A D I N G . . . . . .</h2>
                        </td>
                    </tr>
                </table>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
  <div style="display: none" id="div1">
            <asp:Button ID="btnGetData" runat="server" Text="Button" OnClick="btnGetData_Click" />
        </div>
  </ContentTemplate>
  <%-- <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnGetData" />
        </Triggers>--%>
    </asp:UpdatePanel>

.cs
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        string processId = UpdateProgress1.ClientID;
        string btnId = btnGetData.ClientID;
        string script = string.Format(@"
     var process = document.getElementById('{1}');
     process.style.display = 'block';
     var btn = document.getElementById('{0}');btn.click();
     btn.click();
   ", btnId, processId);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "disableDiv", script, true);
    }
}

2013年9月17日 星期二

[ASP.NET]解決 在UpdatePanel裡放FileUpload控制項卻無法正常上傳檔案 (FileUpload controls in place to solve the UpdatePanel can not upload files in normal)


問題
UpdatePanel非常方便的讓我們做到非同步的效果,但卻在裡面加入FileUpload控制項時,卻無法正常上傳檔案!!如下:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:FileUpload ID="fileUpload1" runat="server" />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
原因是因為預設上,若UpdatePanel沒有設定Triger條件下,預設都是採用
AsyncPostBackTrigger(非同步方式),而像UploadFile這類控制項要將檔案傳回時,則需要採用
PostBackTrigger



解決方法
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
  <asp:FileUpload ID="fileUpload1" runat="server" />
  <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
 </ContentTemplate>
 <Triggers>
      <asp:PostBackTrigger ControlID="btnUpload"  />
 </Triggers>
</asp:UpdatePanel>

2012年5月15日 星期二

[ASP.NET]MasterPage裡加入iFrame連結網頁,並由連結網頁與MasterPage連動(MasterPage was added iFrame links page by page with links MasterPage linked)


問題
當MasterPage裡有設到ajax Timer的元件時,會發現整個頁面發生postback,因此為了減緩此現象,可以在MasterPage加入iFrame,讓另一個網頁取代Timer的動作,因此MasterPage就不會有Postback的現象




解決方法
以下範例示範動態server時間與從另一頁面促發masterpage事件

Site.aspx(放入以下區塊)
<div class="main">
<asp:Label Text="時間表" runat="server"></asp:Label>
<iframe  NAME="bottom" FRAMEBORDER="0"  width="100%" style="height: 50px" src="../WebForm1.aspx"></iframe>
<asp:Label ID="Label1" Text="觸發主頁面" runat="server"></asp:Label>
<iframe  NAME="bottom" FRAMEBORDER="0"  width="100%" style="height: 50px" src="../WebForm2.aspx"></iframe>
<div style="visibility:hidden">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</div>
Site.Master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FramesetDemo
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            this.Label1.Text = "您按下按鈕時間" + DateTime.Now.ToString();
        }
    }
}
WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FramesetDemo.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
                </asp:Timer>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
WebForm1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FramesetDemo
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.Label1.Text = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
        }
    }
}
WebForm2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="FramesetDemo.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <input type="button" onclick="javascript:window.parent.document.getElementById('Button1').click();" name="Button1" value="Button" id="Button1" /></div>
    </div>
    </form>
</body>
</html>
參考: http://forums.asp.net/t/1162285.aspx

2012年4月24日 星期二

[ASP.NET]解決 ToolkitScriptManager引起The status code returned from the server was: 500錯誤(Solve ToolkitScriptManager cause The status code returned from the server was: 500 Error)


問題
Microsoft JScript 執行階段錯誤: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500




解決方法
原ToolkitScriptManager如下:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"
    EnableScriptGlobalization="True" >
</asp:ToolkitScriptManager>
加上EnablePartialRendering="false"如下:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"
EnableScriptGlobalization="True" EnablePartialRendering="false">
</asp:ToolkitScriptManager>

2012年4月9日 星期一

[ASP.NET]如何 讓UpdatePanel裡ImageButton跳出對話視窗(How triger imagebutton popup confirm dialog inner updatepanel)


問題

讓UpdatePanel裡ImageButton跳出對話視窗 一般要做到對話視窗時,會用如下:
if(confirm('登出前,未完成驗收資料將會刪除,確定執行嗎?')==false) return false;

在一般的寫法裡面,我們會將code寫在屬性裡的OnClientClick裡,但是很不幸的在updatepanel此作法無效!!





解決方法

改為寫在code哩,當page_load事件時觸發:
if (!IsPostBack)
{
   Suspend.Attributes.Add("OnClick", "javascript:if(confirm('未完成驗收資料將會放棄,確定執行嗎?')==false) return false; ");
}

2012年4月5日 星期四

[ASP.NET]如何 讓UpdatePanel中另開視窗畫面不閃爍(Solve the UpdatePanel Open the window screen does not flicker)


問題

如何 讓UpdatePanel中另開視窗畫面不閃爍
在UpdatePanel中的Button再點下以後,直接開啟視窗畫面不閃爍




解決方法

.aspx
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
          <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
      </ContentTemplate>
  </asp:UpdatePanel>
.cs
protected void Button1_Click(object sender, EventArgs e){

string strJavaScript = string.Format(@"window.open('{0}','','height=500,width=500,top=100,left=400,toolbar=no,menubar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=no');", "ChoiceImage.aspx");

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", strJavaScript, true);
}

[ASP.NET]如何 讓CalendarExtender顯示中文(How to display Chinese CalendarExtender)


問題
如何 讓CalendarExtender顯示中文



解決方法
把ScriptManager或是ToolkitScriptManager的屬性EnableScriptGlobalization="True"以及EnableScriptLocalization="True"

[ASP.NET]使用 CalendarExtender格式化日期yyyy/MM/dd(Use CalendarExtender date format yyyy / MM / dd)


問題
使用 CalendarExtender格式化日期yyyy/MM/dd



解決方法
.aspx
<asp:TextBox ID="contact_date" runat="server" />
<asp:CalendarExtender ID="contact_date_CalendarExtender" runat="server"
    Enabled="True" Format="yyyy/MM/dd" TargetControlID="contact_date">
</asp:CalendarExtender>

2011年3月14日 星期一

[AJAX]解決 Sys.WebForms.PageRequestManagerParserErrorException: 無法剖析從伺服器收到的訊息。這項錯誤通常的原因是回應被 Response.Write()、回應篩選條件、HttpModules 的呼叫修改了,或是已啟用伺服器追蹤。 詳細資料: 剖析 near 'xxx' 時發生錯誤。(Solve Sys.WebForms.PageRequestManagerParserErrorException: Unable to parse the message received from the server. This error usually occurs because the response is Response.Write (), to respond to the filter criteria, HttpModules call modified, or server trace is enabled. Details: Error parsing near 'xxx'.)


問題
Sys.WebForms.PageRequestManagerParserErrorException: 無法剖析從伺服器收到的訊息。這項錯誤通常的原因是回應被 Response.Write()、回應篩選條件、HttpModules 的呼叫修改了,或是已啟用伺服器追蹤。 詳細資料: 剖析 near 'xxx' 時發生錯誤。



解決方法
在使用ajax開發時,當頁面使用update panel時,而頁面如果有檔案下載的動作,就發出現這樣的問題,因此現有的解決方式就是將update panel移除,就可以避免這樣的問題出現

2010年5月19日 星期三

[ASP.NET]解決 The base class includes the field 'ScriptManager1', but its type (AjaxControlToolkit.ToolkitScriptManager) is not compatible with the type of control (System.Web.UI.ScriptManager).


問題
The base class includes the field 'ScriptManager1', but its type (AjaxControlToolkit.ToolkitScriptManager) is not compatible with the type of control (System.Web.UI.ScriptManager).



解決方法
昨天在修改一個使用ASP.Net,C#,Ajax,Java Scrip開發的Web程式時,發現很怪的問題! 現象是這樣的: 在建置網站的時候,出現錯誤訊息,錯誤訊息來源是某cs檔案裡某Label控制項不存在,或未定義, 另外指出AjaxToolKit reference 錯誤 想當然爾,開啟aspx比對控制項是否遺漏=>結果並未遺漏 仔細看了一下,cs所指出不存在的控制項都包在ajax的update panel裡,看了一下網站的bin檔裡面有AjaxToolKit.dll的檔案,跟AjaxToolKit.reference 打開AjaxToolKit.reference看不懂在寫什麼像是...\.0\.\.AjaxToolKit.dll的東西 想說把AjaxToolsKit重新指定看看,就把該檔案給刪除!! 刪除之後,在c碟裡建ajax的資料夾, 把ajaxtoolkit的資料放在入,再從網站/右鍵/bin裡/加入現有項目的方式加入dll, 之後移除Visual Studio 2008工具箱裡的AjaxToolKit, 在加入一次,指向c:\ajax\AjaxToolsKit.dll 再建置試試看,結果建置以後,問題換另一個了!!
The base class includes the field 'ScriptManager1', but its type (AjaxControlToolkit.ToolkitScriptManager) is not compatible with the type of control (System.Web.UI.ScriptManager).
 
恩~這真是.... 檢查了一下,原來是master.page裡有用ScriptManage, 後來乾脆將之移掉,改用AjaxToolsKit裡的ToolsScriptManager代替 再建置一次..........滴滴滴.....好了?? 所以....問題就是因為AjaxToolsKit的位置從上一個開發環境到另一個開發環境都會發生的問題嗎??

[VISUAL STUDIO]解決 無法從組件 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 載入型別 'System.Web.UI.ScriptReferenceBase'。


問題

無法從組件 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 載入型別 'System.Web.UI.ScriptReferenceBase'。

從Visual Studio 2008安裝好以後,執行程式發現以下的錯誤訊息
無法從組件 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 載入型別 'System.Web.UI.ScriptReferenceBase'。

描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。

例外詳細資訊: System.TypeLoadException: 無法從組件 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 載入型別 'System.Web.UI.ScriptReferenceBase'。

原始程式錯誤:
在執行目前 Web 要求期間,產生未處理的例外狀況。如需有關例外狀況來源與位置的資訊,可以使用下列的例外狀況堆疊追蹤取得。

堆疊追蹤:
[TypeLoadException: 無法從組件 'System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 載入型別 'System.Web.UI.ScriptReferenceBase'。]
AjaxControlToolkit.ToolkitScriptManager.OnResolveScriptReference(ScriptReferenceEventArgs e) in c:\AjaxControlToolkit_Admin\Release\AjaxControlToolkit\ToolkitScriptManager\ToolkitScriptManager.cs:190
System.Web.UI.ScriptManager.RegisterScripts() +261
System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +117
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +2063008
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2247


解決方法

google查了一下,說是未安裝Visual Studio 2008 sp1的原因
到microsoft查了一下Visual Studio 2008 sp1的更新內容
概觀
本下載可讓您安裝 Visual Studio 2008 SP1 以及 .NET Framework 3.5 Service Pack 1 (SP1)。SP1 修正來自客戶及夥伴所回報的問題和內部測試時所發現的重要問題。此 Service Pack 提供 Visual Studio 及 .NET Framework 使用者更好的回應速度、穩定性及效能。

按一下 這裡以取得更多有關 Service Pack 的資訊。 重要事項
如果您之前曾經安裝 Visual Studio 2008 Hotfix 或 Visual Studio 2008 SP1 發行前版本,那麼您必須先執行 Service Pack 準備工具,才能安裝 Visual Studio 2008 SP1。
如果您已安裝多種 Visual Studio 產品,則必須將這些產品全部升級為 SP1。如果您有 Visual Studio 2008 以及一個或多個 2008 Express 版,則在升級 Visual Studio 之前,您都無法升級這些 Express 版。
安裝之前,請仔細閱讀包含在內的讀我檔案,確保您了解本版本的已知問題。
下列技術已經過測試,確保與 SP1 的相容性:

Silverlight 2 SDK Beta 2 與 Silverlight Tools Beta 2. (如果已經安裝了 Silverlight Tools Beta 2,您必須在安裝 Visual Studio 2008 SP1 之後將它升級。若要升級,請使用 Microsoft 下載中心網站之 Silverlight Tools Beta 2 頁面提供的安裝程式)。
MVC Preview Release 第 3 版
ASP.NET 擴充/動態資料預覽
VC 2008 功能套件
VB PowerPack 控制項 (2.0 和 3.0)
Expression Studio 2 (RTM)
SQL Server 2008
.NET Framework 3.5 SDK
XSLT 分析工具
VSTA 2.0 SDK
Visual Studio 2008 SDK

如果您下載並安裝 Microsoft Visual Studio 2008 Service Pack 1,您也應該同時下載並安裝適用於本 Service Pack 中 Intellisense 的 Hotfix。安裝 SP1 時,有些之前已經翻譯的 Intellisense 檔案內容將會回復為英文。此 Hotfix 會更新這些 Intellisense 檔案,因此這些更新內容已完整當地語系化。此 Hotfix 的下載位置為:http://code.msdn.microsoft.com/KB957507/Release/ProjectReleases.aspx?ReleaseId=1854。知識庫文章http://support.microsoft.com/kb/957507 有提供此 Hotfix 所修正之問題的詳細資訊。
如果在安裝 SP1 時發生問題,請解除安裝不包括在以上列出項目中的技術以及/或開發增益集,然後再次嘗試執行 SP1 安裝程式。在確認其他技術與 SP1 相容後,這些技術就會新增到清單中。

 
所幸安裝NET Framework 3.5 Service Pack 1 解決 結果在安裝完以後,錯誤訊息就消失了,使用上目前都很正常

熱門文章