Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何调用按钮';s单击另一页的链接按钮而不返回c#ASP.NET中的post时的单击事件_Javascript_C#_Asp.net_Ispostback - Fatal编程技术网

Javascript 如何调用按钮';s单击另一页的链接按钮而不返回c#ASP.NET中的post时的单击事件

Javascript 如何调用按钮';s单击另一页的链接按钮而不返回c#ASP.NET中的post时的单击事件,javascript,c#,asp.net,ispostback,Javascript,C#,Asp.net,Ispostback,我在母版中有一个LinkButton,点击LinkButton,我会重定向到,比如说,Page1.aspx。在Page1.aspx上,我有一个按钮1。单击该按钮1,我将打开新窗口,不会影响Page1.aspx的数据 但当我点击母版页的LinkButton,重定向到Page1.aspx,然后从代码隐藏处,点击button1,Page1.aspx的数据会发生变化 如何预防这种情况。我正在提供我的代码 母版页上的链接按钮: <asp:LinkButton ID="lnkAppointMent"

我在母版中有一个
LinkButton
,点击LinkButton,我会重定向到,比如说,
Page1.aspx
。在Page1.aspx上,我有一个
按钮1
。单击该
按钮1
,我将打开新窗口,不会影响
Page1.aspx
的数据

但当我点击母版页的
LinkButton
,重定向到
Page1.aspx
,然后从代码隐藏处,点击
button1
Page1.aspx
的数据会发生变化

如何预防这种情况。我正在提供我的代码

母版页上的链接按钮:

<asp:LinkButton ID="lnkAppointMent" runat="server" OnClick="lnkAppointMent_Click"><span>Appointment Scheduler </span></asp:LinkButton>
重定向页面的页面加载(PhoneMessage.aspx):

PhoneMessage.aspx上的按钮:

<div style="float: right; padding-right: 120px">
                                <asp:Button ID="btnScheduleAppointments" runat="server" OnClick="btnScheduleAppointments_Click"
                                    CssClass="button" Text="Schedule Appointments" ToolTip="Open appointment scheduler" />
                            </div>
protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
        {
            try
            {
                base.RaisePostBackEvent(source, eventArgument);
            }
            catch (Exception ex)
            {


            }

.

.
p、 s:当我点击
btnscheduleappoint
时,
source
将是
scheduleappoint
,如果我点击
lnkappoint
source
将是
Appointment Scheduler
,即使我在点击
lnkappoint
时调用
btnscheduleappoint

单击事件按钮:

protected void btnScheduleAppointments_Click(object sender, EventArgs e)
        {
            if (!Permissions.checkPermissions(Session["employeeloggedin"].ToString(), "PHMSGVMD"))
            {
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "OnLoad", "alert('You must have the Phone Messages: View and Modify permission to schedule appointments!')", true);
            }
            else
            {
                string script = String.Format("openNewWin('" + "phonescheduler.aspx" + "')");
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "openNewWin", script, true);
            }

        }
脚本:

function openNewWin(url)
        {
            alert(url);
            var open_link = window.open('', '_blank');
            open_link.location = url;
        }

需要任何澄清。请评论。

我花了一些时间来模拟您的问题。加载Page1.aspx后,您是否尝试修改LinkButton href或atributes

我假设你的Page1.aspx是你的PhoneMessage.aspx,所以当你从母版页点击Lnkapointment时,它会转到“PhoneMessage.aspx”并执行该方法,如果你再次点击它,它只会发回,而不会像以前那样做,基本上,你需要再次重定向到“PhoneMessage.aspx”

那么,为什么不这样修改零件:

                    else if (Session["PhoneCenter"].ToString() == "Appointment")
                    {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "NoExec", String.Format("document.getElementById('lnkAppointMent').href=window.location.href;"), true);
                btnScheduleAppointments_Click(btnScheduleAppointments, null);
                    }
这将使链接再次重定向到Page1.aspx,并且在不回发的情况下执行相同的操作。这不是最优雅的解决方案,但它在您的案例中起到了作用。只需确保有会话[“电话中心”]=“约会”

因此,这不是你问题的答案,但我认为是解决你问题的办法

它对我有用,我希望它对我有帮助!让我知道你的想法


谢谢您的努力,先生。这里的“NoExec”是什么?string script=string.Format(“openNewWin(“+”phonescheduler.aspx“+”)”);ScriptManager.RegisterStartupScript(this.Page,this.GetType(),“openNewWin”,script,true);我在PhoneMessage.aspx的页面加载中尝试了这个。使用此选项,我的页面数据不会被刷新。
function openNewWin(url)
        {
            alert(url);
            var open_link = window.open('', '_blank');
            open_link.location = url;
        }
                    else if (Session["PhoneCenter"].ToString() == "Appointment")
                    {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "NoExec", String.Format("document.getElementById('lnkAppointMent').href=window.location.href;"), true);
                btnScheduleAppointments_Click(btnScheduleAppointments, null);
                    }