2013-01-20 40 views
1

我有一個更新面板和一個菜單。
我想重定向到另一個頁面,當用戶在用戶控制網格視圖打印按鈕點擊(在我更新面板)
我使用這些代碼,但他們並沒有爲我工作:Asp.Net:重定向到更新面板中的usercontrol的另一個頁面

1 : Response.Redirect("PrintTicket.aspx"); 
2 : Response.Write("<script>window.open('PrintTicket.aspx','_parent');</script>"); 
3 : Page.Response.Redirect("PrintTicket.aspx", true); 
4 : Page.ClientScript.RegisterStartupScript(typeof(Page), "ClientScript", "<script  language='javascript' type='text/javascript'>window.location.replace('http://vinaticket.ir /PrintTicket.aspx');</script> ", false); 
5 : ScriptManager.RegisterStartupScript(this, this.GetType(),  "redirect","window.location='" + Request.ApplicationPath + "PrintTicket.aspx';", true); 
6 : Page.ClientScript.RegisterStartupScript(typeof(Page), "ClientScript", "<script  language='javascript' type='text/javascript'> postRefId('" + Session["TicketID"].ToString() +  "');</script> ", false); 
7 : ScriptManager.RegisterStartupScript(this, this.GetType(), "redir", "document.location = 'PrintTicket.aspx'", true); 

這是我的代碼:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true"  UpdateMode="Conditional"> 
<ContentTemplate> 
----menu .... with exit button 
    <asp:PlaceHolder ID="PlaceHolder1" runat="server" ViewStateMode="Enabled"> 

    </asp:PlaceHolder> 

</ContentTemplate> 
<Triggers> 
    <asp:PostBackTrigger ControlID="exit" /> 
</Triggers> 
</asp:UpdatePanel> 
//code behind to loade user control 
private string LastLoadedControl 
{ 
    get 
    { 
     return ViewState["LastLoaded"] as string; 
    } 
    set 
    { 
     ViewState["LastLoaded"] = value; 
    } 
} 

private void LoadUserControl() 
{ 
    try 
    { 
     string controlPath = LastLoadedControl; 

     if (!string.IsNullOrEmpty(controlPath)) 
     { 
      PlaceHolder1.Controls.Clear(); 
      UserControl uc = (UserControl)LoadControl(controlPath); 
      PlaceHolder1.Controls.Add(uc); 
     } 
    } 
    catch (Exception ex) { } 
} 

我的菜單按鈕:

protected void your_ticket_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      Session["pg"] = "Z_ViewTicket.ascx"; 
      setPath(); 
     } 
     catch (Exception ex) { } 
    }
    and set path method():

protected void setPath() { try { string controlPath = string.Empty; controlPath = BASE_PATH + Session["pg"].ToString(); LastLoadedControl = controlPath; LoadUserControl(); } catch (Exception ex) { } }

注:我測試了一個示例代碼,我發現原因,在我的示例代碼中,我拖動用戶控件到我的更新面板和按鈕工作,但當我通過這些代碼調用用戶控件時,該按鈕不起作用(在 情況下,一個用戶控制寄存器的主網頁,但在情況下,兩個有 不在主網頁的任何註冊碼)

,並針對此問題我如何可以重定向到其他網頁?

+0

當在頁面生命週期你調用這些?你嘗試過[RegisterClientScriptBlock()](http://msdn.microsoft.com/en-us/library/btf44dc9.aspx)嗎? –

+0

我不明白你的意思?你能解釋一下嗎? –

+0

你得到的例外是什麼? –

回答

0

我會做一些大膽的假設爲「缺乏例外的」,但讓我們試試看:

  1. JIT debugging disabled for script in Visual Studio
  2. 你有disabled debugging in Internet Explorer

參考對於真正的問題,您可能會將數據源綁定到Page_Load事件中的GridView(請檢查此answer)。

內,您的用戶控件(或任何你要綁定數據到GridView),你有GridView控件綁定到數據源之前檢查!Page.IsPostback

if (!IsPostBack) 
{ 
    gridView.DataSource = new[] { new { Id = 1, Value = "test" } }; 
    gridView.DataBind(); 
} 
+0

我只是在Firefox中測試不是IE,我在另一個項目中做了一個示例,它是工作,但在我的項目中不起作用。 :(( –

相關問題