如何让HTML链接(锚)做了回发到像LinkBut​​ton的? [英] How to let Html Link (anchor) do a postback to be like LinkButton?

查看:159
本文介绍了如何让HTML链接(锚)做了回发到像LinkBut​​ton的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下怎样才能让一个HTML锚(a元素),甚至任何对象做回发或执行服务器端方法?
我想创建一个自定义按钮(带一些div一个包裹,做一些自定义它们),我想实现的OnClick是看起来像ASP.NET LinkBut​​ton的?

如同

 < A HREF =#的onclick =RunServerSideMethod()>只是一个简单的链接按钮< / A>


解决方案

默认情况下,控件使用__doPostBack做回发到服务器。 __doPostBack作为控制的UniqueID(或HTML,HTML元素的name属性)。第二个参数是命令火的名称。

因此​​,对于一个自定义按钮,使输出流:

 <一个ID =someclientidNAME =someuniqueid的href =JavaScript的:无效(0);的onclick =__ doPostBack('someuniqueid','');> VAL&下; / A>

在自定义按钮,添加IPostBackEventHandler,这__doPostBack语句将自动触发其RaisePostBackEvent方法适合你。

I would like to ask how can i make an html anchor (a element) or even any object to do a postback or to execute an server side method? I want to create a custom button (a wrapped with some divs to do some custom them) and i want to implement OnClick to be look like the ASP.NET LinkButton?

Like

<a href="#" onclick="RunServerSideMethod()">Just a simple link button</a>

解决方案

By default, controls use __doPostBack to do the postback to the server. __doPostBack takes the UniqueID of the control (or in HTML, the name property of the HTML element). The second parameter is the name of the command to fire.

So for a custom button, render to the output stream:

<a id="someclientid" name="someuniqueid" href="javascript:void(0);" onclick="__doPostBack('someuniqueid', '');">val</a>

In your custom button, add the IPostBackEventHandler, and this __doPostBack statement will fire its RaisePostBackEvent method automatically for you.

这篇关于如何让HTML链接(锚)做了回发到像LinkBut​​ton的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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