双击一个图片然后跳转到另一个页面去
首先看看效果:
.aspx:
<img src="Images/Harmony.png" id="Harmony" runat="server"/>
可以使用Web控件,也可以用Html签标,要添加上ID与runat属性,这样可以在cs获以这图片的ID。
.aspx.cs:
View Code
protected void Page_Init(object sender, EventArgs e)
{
this.Harmony.Attributes.Add("ondblclick", Page.ClientScript.GetPostBackEventReference(this.Harmony, "ondblclick"));
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
var ctrl = Request.Params[Page.postEventSourceID];
var args = Request.Params[Page.postEventArgumentID];
OndblclickHandle(ctrl, args);
}
}
private void OndblclickHandle(string ctrl, string args)
{
if (ctrl == this.Harmony.UniqueID && args == "ondblclick")
{
Response.Redirect("~/Default2.aspx?Id=" + 2012);
}
}
{
this.Harmony.Attributes.Add("ondblclick", Page.ClientScript.GetPostBackEventReference(this.Harmony, "ondblclick"));
}
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
var ctrl = Request.Params[Page.postEventSourceID];
var args = Request.Params[Page.postEventArgumentID];
OndblclickHandle(ctrl, args);
}
}
private void OndblclickHandle(string ctrl, string args)
{
if (ctrl == this.Harmony.UniqueID && args == "ondblclick")
{
Response.Redirect("~/Default2.aspx?Id=" + 2012);
}
}
其实,你可以使用最简单的方法:
<img id="Harmony" src="Images/Harmony.png" ondblclick="location.href='Default2.aspx?id=2012'" />