2012-08-31 22 views
0

我有一個通用的功能(自定義控件的功能),從應用程序中的各種網頁調用。
在公共功能,我這樣調用(示例代碼)一個javascript -
從UpdatePanel調用函數?

public void ShowMessage(string strMessage) 
{ 
    string s=String.Empty; 
    s="<script type='text/javascript'>\n"; 
    s = s + "alert('+strMessage+');"; 
    s = s + "</script>"; 
    Page.ClientScript.RegisterStartupScript(typeof(Page), this.ClientID, s); 
} 


當我打電話從使用的UpdatePanel頁面此功能,Page.RegisterStartUpScript沒有工作。 所以,我必須使用
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), this.ClientID, s, false);
現在,我必須通過一個參數來確定功能是從UpdatePanel的調用。
像這個 -

public void ShowMessage(string strMessage,bool isFromUpdatePanel){..} 

我的問題是,在公共功能,我可以知道這個功能是否從UpdatePanel的或不叫(不使用參數)?

回答

0

我找到了答案,我會用這個(got from Here) -

string args= Page.Request.Params.Get("__EVENTTARGET"); 
if (!String.IsNullOrEmpty(args)) 
{ 
    //Called From Update Panel(or) UpdatePanel is posting back 
} 
else 
{ 
    //Called From a page with no Update Panel 
} 

如果有一個更好的解決方案,請教我。