简体   繁体   English

如何在INamingContainer中使用ClientScript.getpostbackclienthyperlink

[英]How to use ClientScript.getpostbackclienthyperlink inside INamingContainer

I have a custom WebControl class which inherits from WebControl and INamingContainer. 我有一个自定义WebControl类,该类继承自WebControl和INamingContainer。 Inside this class is a gridview which I want to have clickable rows. 在此类的内部是一个gridview,我希望它具有可单击的行。

I have the gridviews AutoGenerateSelectButton set to True for the time being, but eventually I want to replace this with a row onclick event which posts back to the server. 我暂时将gridviews AutoGenerateSelectButton设置为True ,但是最终我想将其替换为行onclick事件,该事件会发回到服务器。

In the gridviews RowCreated event I have the following code to add my desired onclick event to each row: 在gridviews RowCreated事件中,我有以下代码将所需的onclick事件添加到每一行:

e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.gvUserList, "Select$" + e.Row.RowIndex);

Unfortunately, this doesnt work and generates a slightly different output to the select button due to my class inheriting from INamingContainer. 不幸的是,由于我的类是从INamingContainer继承而来的,所以这行不通并且对选择按钮生成的输出稍有不同。

The generated output from the select button (which works) is: 选择按钮(有效)的生成输出为:

onclick="__doPostBack('UserData$gvUserList','Select$2');"

Whereas the code generated from the ClientScript.GetPostBackClientHyperlink method is this: 而从ClientScript.GetPostBackClientHyperlink方法生成的代码是这样的:

onclick="__doPostBack('gvUserList','Select$2');"

Notice that the javascript for the select button prefixes the gridviews name with 'UserData$' (The ID given to my control from the page itself) because of the INamingContainer interface, while the postback client hyperlink does not. 请注意,由于具有INamingContainer接口,因此select按钮的javascript在gridviews名称前添加了“ UserData $”(从页面本身提供给我的控件的ID),而回发客户端超链接则没有。

How can I achieve the same generated output as the select button does with the GetPostBackClientHyperlink method? 如何使用GetPostBackClientHyperlink方法获得与选择按钮相同的生成输出?

Since I have not been able to come up with an elegant solution to this, I have fixed it using the following code: 由于我无法为此提出一个优雅的解决方案,因此我使用以下代码对其进行了修复:

e.Row.Attributes["onclick"] = "__doPostBack('" + this.UniqueID + "$" + gvUserList.ID + "', 'Select$" + e.Row.RowIndex + "')";

This is the best I could come up with. 这是我能想到的最好的。 I still welcome other answers! 我仍然欢迎其他答案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM