在ASP.NET强制客户端ID [英] Forcing client ids in ASP.NET

查看:179
本文介绍了在ASP.NET强制客户端ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在ASP.NET的下一个版本,我们将最终能够设置的System.Web控制的ClientID无框架准智能的方式例如这样做是为了我们:

I know that in the next version of ASP.NET we'll finally be able to set the clientids on System.Web controls without the framework doing it for us in a quasi-intelligent way e.g:

id="ctl00__loginStatus__profileButton"

有谁知道在此之前的好方法,迫使上述ID喜欢的东西。

Does anyone know a good method in the meantime to force the above id to something like

id="profileButton"

造成这种情况的主要原因是jQuery中的的ClientID时动态添加控件到页面的操作。我可以看到正在发生变化的ID将打破视图状态的问题?

The main reason for this is manipulation of the clientids in jQuery when dynamically adding controls to a page. The problem I can see is changing the ids will break the Viewstate?

推荐答案

我倾向于做的是动态生成它处理这个​​JavaScript方法是什么。您可以在标记或code这样做的背后因此,例如:

What I tend to do is dynamically generate javascript methods which handle this. You can do this in markup or code behind so for example:

<script language="javascript" type="text/javascript">
function doXYZ()
{
   $("#" + getListBoxId()).css(...)
}

function getListBoxId()
{
 return "<%=this.myListBox.ClientId>";
}

</script>

您也可以建立在后面的code中的功能和注册。

You can also build the functions in the code behind and register them.

修改

几个月前,我需要解决一些服务器控件的ID,我设法破解它,我这里介绍我的方法的这里

A couple months ago I needed to fix the id of some server controls, I managed to hack it in and I described my method here here.

基本上你需要把控制如用户控件的命名容器里面,然后覆盖几个属性的其中prevents子控件从得到他们的UNIQUEID。

Basically you need put the controls inside a naming container like a user control, and then override a couple of properties which prevents the child controls from getting their uniqueid.

这篇关于在ASP.NET强制客户端ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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