Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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
C# 不工作-在服务器上单击属性_C#_Html_Asp.net - Fatal编程技术网

C# 不工作-在服务器上单击属性

C# 不工作-在服务器上单击属性,c#,html,asp.net,C#,Html,Asp.net,我想在应答器中添加服务器上的单击事件,如下所示: <a onServerClick="verif" runat="server" href="/annexe/Ajouter/ajout_agence.aspx">Ajouter agence</a> 在else中,我希望自动重定向到href链接 谢谢你的帮助。你在找这个吗 else { Response.Redirect(yourURL); } 使用MessageBox.Show将不起作用

我想在应答器
中添加服务器上的
单击事件,如下所示:

<a onServerClick="verif" runat="server" href="/annexe/Ajouter/ajout_agence.aspx">Ajouter agence</a>
else
中,我希望自动重定向到
href
链接


谢谢你的帮助。

你在找这个吗

else
    {
       Response.Redirect(yourURL);
    }

使用
MessageBox.Show
将不起作用。消息框将出现在服务器上(它根本不会出现,因为asp.net不是交互式进程),而不会出现在客户端计算机上。您可以编写一些JavaScript来处理此问题:

<a id="verif" runat="server" href="/annexe/Ajouter/ajout_agence.aspx">Ajouter agence</a>

<script>
  $("#verif").click(function(e)
  {
     //some ajax call to check if valid
     if (!isValid)
     {
        window.alert("Non autorisé!");
        e.preventDefault();
     }
  });
</script>

$(“#verif”)。单击(函数(e)
{
//一些ajax调用来检查是否有效
如果(!isValid)
{
警告(“非自动!”);
e、 预防默认值();
}
});
注意,您需要编写一个ajax服务来检查用户是否有效&返回true或false。您也不应该仅仅依赖于此,还应该在服务器上检查,以防用户篡改页面或手动转到URL。

试试这个,它正在工作

protected void verif(Object sender, EventArgs e)
{
    if (Session["user"].Equals("magasinier"))
    {
        DialogResult result1 = MessageBox.Show("Non autorisé!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
        if (result1 == DialogResult.OK)
        {
            result1 = DialogResult.Ignore;
        }
    }
    else
    { 
        Response.Redirect( ((System.Web.UI.HtmlControls.HtmlAnchor)sender).HRef);//sender is your anchor tag. And take it's href attribute and redirect
    }
}

我不知道你要的是什么…只需使用鼠标,拖动页面上的链接按钮,然后转到属性并添加onclick,双击它,然后编写代码。好的,谢谢你,亚里士多德:)不,事实上verif函数将出现在许多应答器的服务器点击事件上,我希望自动重定向到href。类似于将href作为参数提供给verif函数,并将其用于诸如response.redirect(参数)之类的代码隐藏。谢谢你的回答试试这个:或者这个:好的,谢谢你失眠:)是的,非常感谢西蒙·哈尔西
protected void verif(Object sender, EventArgs e)
{
    if (Session["user"].Equals("magasinier"))
    {
        DialogResult result1 = MessageBox.Show("Non autorisé!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
        if (result1 == DialogResult.OK)
        {
            result1 = DialogResult.Ignore;
        }
    }
    else
    { 
        Response.Redirect( ((System.Web.UI.HtmlControls.HtmlAnchor)sender).HRef);//sender is your anchor tag. And take it's href attribute and redirect
    }
}