开发者

Bind ClientID to UserControl property within a Gridview

I am trying 开发者_如何学编程to bind a string that contains the ClientID of one user control to the property of another control within a GridView template column. I get the error 'lblVar02' is not declared. It may be inaccessible due to its protection level. How do I do this?

<uc:CriteriaType id="ctVar02" runat="server" 
    OnClientChange="<%# &quot;toggle('&quot; & lblVar02.ClientID & &quot;');&quot; %>"></uc:CriteriaType>
<uc:Label ID="lblVar02" runat="server" />


For anyone else having this problem, this could've been solved three different ways that I know of.

  1. Don't pass in the ClientID and change the JavaScript to crawl through the DOM (this.parentNode.getElementsByTagName or something) looking for the other control. This solution seemed flimsy to me since the Id's could possibly change.
  2. Set the property in the RowDataBound event. This would be simple, but my page is huge and since this would occur after TrackViewState(), it would add unneeded bloat to my ViewState.
  3. Move the lblVar02 control inside the ctVar02 control. This is what I ended up doing. I was trying to bind the JavaScript call to my user control property so I could then bind it to a client-side "click" event of a label control inside my user control. By moving the one user control inside of the other I was able to bind the JavaScript call with the ClientID directly to the client-side "click" event of the label.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜