占位符的按钮onclick问题 [英] button onclick issue with placeholders

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

问题描述

我想像动态控件生成一样,我设法将控件放在占位符上.当我尝试从控件中获取信息时遇到的问题是,因为它无法看到"处理程序中的控件.


在test.aspx

I want to make like dynamic control generation and I managed to put my controls on placeholders .the problem I get when I tried to get info back from a control , since it won''t "see" the controls in the handler .

i.e.
in test.aspx

<asp:PlaceHolder ID="PlaceHolder1" runat="server">
<asp:PlaceHolder ID="PlaceHolder2" runat="server"> 


在页面后面的代码中


in code behind the page

protected void Page_Load(object sender, EventArgs e){
TextBox txt = new TextBox();
Button btn = new Button();
btn.OnClientClick = "button_click";
//btn.Attributes.Add("onClick","button_click"); I tried this way , yet didn''t work 
btn.Attributes.Add("runat","server");
PlaceHolder1.Controls.Add(txt);
PlaceHolder1.Controls.Add(btn);}


处理程序是:


and the handler is :

protected void button_click(Object sender , EventArgs args){
string str = txt.Text; // I don''t know if this would work , cuz this method didn''t run onclick
 PlaceHolder2.Controls.Add(new LiteralControl("intered :"+str));
}

推荐答案

错误的事情是事件类型,我正在使用^^''
用于javascript操作
做我用
the wrong thing is type of event I''m using ^^''
it''s for javascript actions
to do my work I used
btn.click += EventHandler(button_click);


的工作 而且有效

至于文字控件,


and it works

as for the text control ,

TextBox tmp = (TextBox) PlaceHolder1.findControl("input");


其中输入"是文本框ID


where "input" is the text box id


首先,"OnClientClick"表示您正在尝试调用客户端jscript方法.
因此,您需要使用事件处理程序注册click事件作为"Timberbird"注释.
与本文一起使用,只需使用Button控件更改linkbutton:
http://aquesthosting.headtreez.com/doc/3309d107-bd26-4d78-ad38-7a82933d5c50 [ ^ ]
First of all "OnClientClick" mean you are trying to call client side jscript method.
So you need to registered click event with event handler as "Timberbird" commentes.
Go with this article just change linkbutton with Button control:
http://aquesthosting.headtreez.com/doc/3309d107-bd26-4d78-ad38-7a82933d5c50[^]


这篇关于占位符的按钮onclick问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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