我有一个更新面板,里面有一个菜单。
当用户单击用户控件(在我的更新面板中)的网格视图中的打印按钮时,我想重定向到另一个页面
我使用了这些代码,但它们对我不起作用:
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)
{
尝试
{
会话["pg"] = "Z_ViewTicket.ascx";
设置路径();
}
捕捉(异常前){}
}
and set path method():
protected void setPath()
{
try
{
string controlPath = string.Empty;
controlPath = BASE_PATH + Session["pg"].ToString();
LastLoadedControl = controlPath;
LoadUserControl();
}
catch (Exception ex) { }
}
注意:我测试了一个示例代码并找到了原因,在我的示例代码中,我将用户控件拖到我的更新面板并且按钮工作,但是当我通过这些代码调用用户控件时,按钮不起作用(以防万一用户控制注册到主页,但如果两个主页中没有任何注册代码)
对于这个问题,我如何重定向到其他页面?