Eval script for server side control's ID property?

我与影子孤独终老i 提交于 2019-11-28 02:23:32

You can't do it.

Why do you need to? If it's so you can reference it at some point, you can access the client-side id via the property ClientID.

Example, as requested:

<asp:Repeater runat="server" ID="repFoo">
    <ItemTemplate>
        <asp:Panel runat="server" ID="pnlFoo">
            <input type = "button"
                onclick = "alert('<%# Container.FindControl("pnlFoo").ClientID %>');"
                value   = "click to get id for <%# Container.ItemIndex %>" />
        </asp:Panel>
    </ItemTemplate>
</asp:Repeater>

As Silky said, you can't do this. The attributes can't be dynamic in none code behind. One solution is to subclass the Panel:

public class MyPanel : Panel
{
    public override string ID
    {
        get
        {
            return "get from my datasource";
        }
        set
        {
            // noop
        }
    }
}

Do you need to use a panel? Could you just use html?

<div id="<%# Eval("RENTER_ID") %>" style="display:none"></div> 

Try this

 <div runat="server" id='<%# Eval("IsVisible") %>' visible="false"> </div>

Try this - It will not popup any messages if you do formatting, but it will show Design time error.

<asp:Panel runat="server" ID='<%# Eval("RENTER_ID") %>' Visible="false">

asp.net controls' ID doesn't support the binding. Try to use HTML controls to work around.

It almost always when asp.net fails , comes Jquery into the field to set the situation up ;) . you can do this trick for example :

In HTML:

<div>
<input type="file" id="whatever" class="uploader" runat="server" />
<span id="<%#Eval("ID")%>'"></span>
</div>

Jquery:

    $('.uploader').on('change', function () {
        var id = $(this).next('span').attr('id');
     });    
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!