gpt4 book ai didi

c# - ASP.NET : Redirect to another page from usercontrol in update panel

转载 作者:行者123 更新时间:2023-11-28 09:25:53 27 4
gpt4 key购买 nike

我有一个更新面板,其中有一个菜单。
当用户单击用户控件中 GridView 中的打印按钮(在我的更新面板中)时,我想重定向到另一个页面
我使用了这些代码,但它们对我不起作用:

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():<p></p>

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

Note: i test a sample code and i find the reason, in my sample code i drag user control to my update panel and the button worked, but when i call user control by these codes the button doesn't work(in case one the user control register to main page but in case two there isn't any register code in main page)

对于这个问题我如何重定向到其他页面?

最佳答案

我将对“缺乏异常(exception)”做出一些大胆的假设,但让我们尝试一下:

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

引用问题的真实主题,您可能在 Page_Load 事件中将数据源绑定(bind)到您的 GridView(检查此 answer )。

在用户控件内(或将数据绑定(bind)到 GridView 的任何位置),在将 GridView 绑定(bind)到数据源之前,必须检查 !Page.IsPostback:

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

关于c# - ASP.NET : Redirect to another page from usercontrol in update panel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14422750/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com