没有调用onserverclick按钮 [英] not calling that onserverclick button

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

问题描述





我希望在C#,asp.net中执行服务器点击事件方法。我为删除按钮创建动态id,但它没有调用该服务器事件,它当前不适合我,但它转到页面加载事件,但不调用onserverclick按钮事件。在click事件中,我编写了一组已调用的代码。



Hi,

i want execute server click event method in C#, asp.net. i create dynamically id for delete button,but its not calling that server event and its not working for me currently, but it goes to page load event, but not calling that onserverclick button event. in click event i write set of code that has be called.

String sFinal=""; 
String sSlider = "<button id=<bid> runat=\"server\" onserverclick=\"btnDelete_ServerClick\" >Delete</button>";
                                    while (i < dt.Rows.Count)
                                    {
                                        sFinal = sFinal + sSlider.Replace("<bid>", "btn" + i.ToString());
                                        i++;
                                    }

推荐答案

Html按钮没有onserverclick方法。请参见 http://www.w3schools.com/tags/tag_button.asp [ ^ ]您可以设置要提交的类型以便将页面发回。



或者,您可以动态添加按钮,但这是通过使用C#代码完成的,而不是构建字符串。 Google用于c#动态添加按钮。
Html buttons do not have a onserverclick method. See http://www.w3schools.com/tags/tag_button.asp[^] You could set the type to submit for it to post the page back.

Or, you can dynamically add a button but this is done by using C# code, not building a string. Google for "c# dynamically add button."


要使ASP.NET引擎识别您的按钮,您必须将它们添加到页面的对象模型而不是字符串...

For the ASP.NET engine to recognize your buttons you have to add them to the object model of your page and not as a string...
while (i < dt.Rows.Count)
{
  Button oBtn = new Button();

  oBtn.ID = string.Format("btn_{0}", i);
  oBtn.Click += new EventHandler(btnDelete_ServerClick);
  // set any other property here...

  Page.Controls.Add(oBtn);
  i++;
}


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

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