从DIV调用ASP.net函数/方法的onclick [英] Call ASP.net function / method from div onclick

查看:862
本文介绍了从DIV调用ASP.net函数/方法的onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的URL重定向一个DIV的onclick。

I have a basic url redirect on a DIV's onclick.

<div onclick="location.href = 'page.aspx';">

我有必要做一些工作服务器端,而不仅仅是一个重定向,该事业部被点击的时候。

I have a need to do some work server side, rather than just a redirect, when this Div is clicked.

我怎么叫我的code一前一后从DIV的onclick功能?该DIV是一个用户控件里面的家长控制。我想我可以修复,它用文字控制和编写查询串入的onclick,但我会用这作为最后的手段,因为我不希望使用的查询字符串。

How do I call one of my code behind functions from the DIV onclick? The DIV is the parent control inside a usercontrol. I suppose I can "fix" it by using a literal control and writing a query string into the onclick, but I would use that as a last resort as I don't want to use a query string.

是否有醒目的DIV单击code后面,我可能已经错过了?其他办法

Are there any other ways of catching a DIV click in code behind that I may have missed?

推荐答案

您可以有它的显示屏可以是无的按钮。 手柄上的客户端点击事业部,然后从那里火灾那个按钮的点击和处理按钮的Click事件的认为服务器端。

You can have a button whose display can be 'none'. Handle click of Div on client side and then from there fire the Click of that button and handle the thinks Server Side on the Click Event of the button.

<asp:Button runat="server" id="btnHidden" style="display:none" onclick="btnHidden_OnClick" />
<div onclick="javascript:DivClicked(); return true;"></div>

<script>

function DivClicked()
{
    var btnHidden = $('#<%= btnHidden.ClientID %>');
    if(btnHidden != null)
    {
        btnHidden.click();
    }
}

</script>

这篇关于从DIV调用ASP.net函数/方法的onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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