超链接点击识别! [英] Hyperlink click recognition !

查看:103
本文介绍了超链接点击识别!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio,ASP.NET

朋友,
我使用PlaceHolder控件,并通过以下代码在Page_load中添加了两个HyperLink控件:

visual studio, ASP.NET

hi friends,
I use PlaceHolder control and add two HyperLink controls in Page_load by this code:

System.Web.UI.WebControls.HyperLink hl = new HyperLink();
PlaceHolder1.Controls.Add(hl);

hl = new HyperLink();
PlaceHolder1.Controls.Add(hl);




现在的问题是我应该如何确认用户单击了哪个超链接! 例如,使用某种方式在超链接单击后更改请求的查询或更改会话!
对不起,我的英语解释不好.
我将不胜感激.




Now the problem is how should i recongnize which hyperlink did user clicked !!??
for example use some way to change requesting query or changing session after hyperlink click !

Sorry for bad explanation and my bad english.
i''ll appreciate any help.
thanks in advanced.

推荐答案

使用HyperLink ID Text 属性,您可以了解实际单击了哪个HyperLink.试试这个:
With the ID or Text property of HyperLink you can come to know which HyperLink is clicked actually. Try this:
HyperLink hl = new HyperLink();
hl.ID = "HyperLnk1";
hl.Text = "HyperLnkText1";
PlaceHolder1.Controls.Add(hl);

hl = new HyperLink();
hl.ID = "HyperLnk2";
hl.Text = "HyperLnkText2";
PlaceHolder1.Controls.Add(hl);



现在,您可以使用Text ID 属性识别超链接.


--Amit



Now you can recognize the hyperlinks using Text or ID property.


--Amit


如果要订阅单击事件,我宁愿使用ASP LinkBut​​ton控件,也不愿使用常规的超链接.示例:
If you want to subscribe to a click event I would rather use the ASP LinkButton control than a regular hyperlink. Example:
protected void Page_Load(object sender, EventArgs e)
{
    LinkButton linkButton = new LinkButton();
    linkButton.Text       = "LinkButton";
    linkButton.Click     += new EventHandler(linkButton_Click);

    PlaceHolder1.Controls.Add(linkButton);
}

void linkButton_Click(object sender, EventArgs e)
{
    LinkButton linkButton = sender as LinkButton;

    if (linkButton.Text == "LinkButton")
    {
        // Open a different page
        Response.Redirect("WebForm2.aspx");
    }
}


这篇关于超链接点击识别!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆