按钮控制事件 [英] button control event

查看:73
本文介绍了按钮控制事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友.

我有一个按钮控件,一个图像按钮,一个链接按钮和一个具有AutoPostBack=true的下拉列表.

当我运行页面时,控件按以下方式呈现.

Hi friend.

I have one button control,one image button, one link button and one dropdownlist which has AutoPostBack=true.

When I run page, controls are render as following ways.

<input type="submit" name="Button1" value="Click" id="Button1" />
    <input type="image" name="btnImage" id="btnImage" src="images/addthis.gif" style="border-width:0px;" />
    
    <select name="drp" onchange="javascript:setTimeout(''__doPostBack(\''drp\'',\''\'')'', 0)" id="drp">
</select>
    
<a id="lnk" href="javascript:__doPostBack(''lnk'','''')">Link</a>



现在,您可以在上面的代码中看到dropdownlist和link按钮使用__doPostBack函数呈现,该函数处理其事件.但是按钮控件或图像控件没有任何处理事件的功能或控件.

所以我的问题是,如果我放置10个以上的按钮和图像按钮,那么页面如何识别单击哪个按钮并引发特定事件?

谢谢
Imrankhan



Now, You can see in above code that dropdownlist and link button are render with __doPostBack function which is handle its event. but button control or image control does not have any function or control to handle event.

So my question is that If I put more than 10 button and image button so how page identify which button is clicked and raised particular event?

Thanks
Imrankhan

推荐答案

默认情况下,Button控件是 Submit button.提交按钮没有与该按钮关联的命令名称(由CommandName属性指定),只是将网页重新发布回服务器.您可以为Click事件提供事件处理程序,以编程方式控制单击提交"按钮时执行的操作.

请阅读以下详细信息: MSDN:按钮类 [ ^ ]
By default, a Button control is a Submit button. A Submit button does not have a command name (specified by the CommandName property) associated with the button and simply posts the Web page back to the server. You can provide an event handler for the Click event to programmatically control the actions performed when the Submit button is clicked.

Please read this for more details: MSDN: Button Class[^]


亲爱的,

虽然我无法理解您的目的,但是如果您想知道服务器上客户端PC上单击了哪个按钮,可以使用
Dear,

Although I couldn''t understand your purpose, but if you want to know on server which button was clicked on client PC, you can use
<asp:Button ID="btn" Text="ClickMe" OnClientClick="__doPostBack(this.id, null)" runat="server" />


在服务器上,您可以使用:


and on the server you can use:

If Request("__EVENTTARGET") = btn.ClientID Then
     'Do Something ...
End If



谢谢



Thanks


这篇关于按钮控制事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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