可能是一個簡單的疏忽,我已經錯過了(雖然我依稀記得大概的Response.Write的內部工作按預期在某些情況下不工作一些不起眼的博文,但我不記得這是否是其中之一):SP2010 - httpcontext.response.write()不工作的LinkButton的的onClick事件
情況是,我在SP2010中運行的控件上有一個鏈接按鈕,如果我不使用HttpContext.Response.Write(),一切正常如預期的那樣(即我可以更改標籤的.Text值)。但是,如果我調用Context.Response.Write(),而我可以調試並逐步執行代碼,則似乎什麼也不會發生(沒有任何信息會被寫回來,並且不會顯示其他控件的更改)。它在_layouts中的應用程序頁面上運行,出現在模態對話框中。
(基本上,我試圖做到這一點 - http://acveer.wordpress.com/2011/01/25/using-the-sharepoint-2010-modal-dialog/但它不工作編輯:如果我將其更改爲一個ASP:按鈕,它仍然無法正常工作。)
下面是一些代碼,如果你有興趣:
的.aspx:
@ Page Language="C#" AutoEventWireup="true" ...
<asp:LinkButton CssClass="button remove" runat="server" OnClick="remove_Click" Text="Remove" ID="remove"></asp:LinkButton>
.aspx.cs:
public void remove_Click(object sender, EventArgs e)
{
....
//if successful
HttpContext context = HttpContext.Current;
if (HttpContext.Current.Request.QueryString["IsDlg"] != null)
{
testControl.Text = "test code";
//doesn't work, and prevents line above from working
Context.Response.Write("<script type='text/javascript'>alert('hi!');</script>");
Context.Response.Flush();
Context.Response.End();
// context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");
// context.Response.Flush();
// context.Response.End();
}
}
一nyone碰到類似的東西?
編輯:一些更有趣的作品,可以幫助,
- 按鈕本身處於一個UpdatePanel
- 我有一個AsyncPostbackTrigger分配
我希望我能給這100個upvotes - 非常感謝你!學到了堆:D – 2012-08-09 02:22:48