调用处理程序而不使用 Response.Redirect?
可能的重复:
如何从内部调用 ASHX ASPX.VB 函数?
看看我下面的代码,我的问题很明显,如何在不重定向的情况下调用ashx文件?我需要按此顺序执行代码,但是当页面重定向时,重定向下方的所有内容都不会执行。提前致谢。
protected void btnAddMach_Click(object sender, EventArgs e)
{
InsertMachine();
if (cbMachIcal.Checked && !cbMachGcal.Checked)
{
Response.Redirect("iCal.ashx?type=Lead&leadID=" + Convert.ToInt32(hfLeadID.Value) + "&date=" +
txtMachTickDate.Text + "&time=" + txtMachTickTime.Text + "&user=" +
Request.Cookies["upProspektor"]["userName"] + "&model=" +
ddlModel.SelectedItem.Text);
}
else if (!cbMachIcal.Checked && cbMachGcal.Checked)
CreateGcalEvent();
else if (cbMachIcal.Checked && cbMachGcal.Checked)
{
CreateGcalEvent();
Response.Redirect("iCal.ashx?type=Lead&leadID=" + Convert.ToInt32(hfLeadID.Value) + "&date=" +
txtLeadTickDate.Text + "&time=" + txtLeadTickTime.Text + "&user=" +
Request.Cookies["upProspektor"]["userName"] + "&model=" +
ddlModel.SelectedItem.Text);
}
ClearControls(upMachDetails);
UpdateHasMach();
btnUpComm.Style.Add("display", "none");
btnNewMach.Style.Add("display", "none");
btnUpMach.Style.Add("display", "none");
if (hfAddMach.Value.ToString() == string.Empty)
{
hfAddMach.Value = "1";
dvPl = dvProLeads(cmdProLeads());
gvProLeads.DataSource = dvPl;
gvProLeads.DataBind();
this.upReports.Update();
}
Utilities.DisplayAlert(this, this.GetType(), "Machine Info Entered Successfully!");
}
Possible Duplicate:
How do I call an ASHX from inside an ASPX.VB function?
Take a look at my code below, my problem is quite obvious, how can I make a call to the ashx file without redirecting? I need the code to execute in this order but when the page redirects, everything below the redirect does not get executed. Thanks in advance.
protected void btnAddMach_Click(object sender, EventArgs e)
{
InsertMachine();
if (cbMachIcal.Checked && !cbMachGcal.Checked)
{
Response.Redirect("iCal.ashx?type=Lead&leadID=" + Convert.ToInt32(hfLeadID.Value) + "&date=" +
txtMachTickDate.Text + "&time=" + txtMachTickTime.Text + "&user=" +
Request.Cookies["upProspektor"]["userName"] + "&model=" +
ddlModel.SelectedItem.Text);
}
else if (!cbMachIcal.Checked && cbMachGcal.Checked)
CreateGcalEvent();
else if (cbMachIcal.Checked && cbMachGcal.Checked)
{
CreateGcalEvent();
Response.Redirect("iCal.ashx?type=Lead&leadID=" + Convert.ToInt32(hfLeadID.Value) + "&date=" +
txtLeadTickDate.Text + "&time=" + txtLeadTickTime.Text + "&user=" +
Request.Cookies["upProspektor"]["userName"] + "&model=" +
ddlModel.SelectedItem.Text);
}
ClearControls(upMachDetails);
UpdateHasMach();
btnUpComm.Style.Add("display", "none");
btnNewMach.Style.Add("display", "none");
btnUpMach.Style.Add("display", "none");
if (hfAddMach.Value.ToString() == string.Empty)
{
hfAddMach.Value = "1";
dvPl = dvProLeads(cmdProLeads());
gvProLeads.DataSource = dvPl;
gvProLeads.DataBind();
this.upReports.Update();
}
Utilities.DisplayAlert(this, this.GetType(), "Machine Info Entered Successfully!");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最初的想法是,这听起来像是一个有缺陷的设计。您将浏览器重定向到 ASHX 文件,然后尝试继续执行当前页面(包括向页面输出内容)。我建议重构代码来解决这个问题。
...但是...
如果您绝对必须在页面早期重定向并仍然在原始页面中执行一些代码,则可以使用
Response.Redirect(string, bool)
使页面在调用时不会自动停止执行。我仍然建议重构代码而不是这种方法。
My initial thought is that this sounds like a flawed design. You're redirecting the browser to the ASHX file, then trying to continue your current page's executing (including outputting things to the page). I would recommend refactoring the code to fix this.
...BUT...
If you absolutely MUST redirect early in a page and still execute some code in the original page, you can use
Response.Redirect(string, bool)
to cause the page to not automatically stop executing when called.I would still recommend refactoring the code instead of this method.