问题在ASP.NET C#得到.ClientID [英] Issue getting .ClientID in ASP.NET C#

查看:706
本文介绍了问题在ASP.NET C#得到.ClientID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在uploadError时javascript函数从AJAX工具包AsyncFileUpload如下:

I have the following in the uploadError javascript function for AsyncFileUpload from AJAX toolkit:

function uploadError(sender, args) {
    document.getElementById("<%# uploadResult.ClientID %>").innerText = args.get_fileName(), "<span style='color:red;'>" + args.get_errorMessage() + "</span>";
}

不幸的是,客户端ID 调用返回,所以JavaScript错误。

Unfortunately the ClientID call returns Null, so the javascript errors.

我也注意到,没有我的控制有通常的.NET格式一旦加载页面:如:

I have also noticed that none of my controls have the usual .NET format once the page is loaded: E.G.:

<asp:Label runat="server" Text="Select an image to upload it to this stock item...." ID="uploadResult" /> 

通常会呈现这样的:

Would usually render like this:

<span id="ctl00_ContentPlaceHolder1_uploadResult">Choose a webstock file to upload...</span>

但有了这个文件,它呈现为:

But with this file it is rendering as:

<span id="uploadResult">Select an image to upload it to this stock item....</span>

我presume这是同样的问题,但不知道为什么它的发生。

I presume this is the same issue, but don't know why it's happening.

推荐答案

现在的问题是,你正在使用的&LT;%#语法,只执行约束力(evals )。

The problem is you are using the <%# syntax which is only executed on binding (evals).

您应该使用&LT;%= 语法,这将永远执行

You should be using <%= syntax which will always execute.

例如:

function uploadError(sender, args)
{
    document.getElementById('<%= uploadResult.ClientID %>').innerText = 
        args.get_fileName() + "<span style='color:red;'>" + 
        args.get_errorMessage() + "</span>";
}

<一个href="http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-%283c25242c-3c253d2c-3c252c-3c252c-etc%29.aspx">Reference关于asp.net在线语法的更多信息。

数据绑定语法

内联语法

编辑:请注意你有提交作业的innerText 这也将是一个问题,如果它不是一个错字。

Note you had , in your assignment to innerText which would also be an issue if it is not a typo.

这篇关于问题在ASP.NET C#得到.ClientID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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