且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将值分配给javascript变量在C#代码隐藏

更新时间:2023-02-11 22:38:35

我看到你要检索GRP的值是一个自定义属性。您需要使用的getAttribute功能 - 所以不是 _Obj.Grp ,您需要使用 _Obj.getAttribute(GRP)

I see that you want to retrieve value of Grp that is a custom attribute. You need to use getAttribute function - so instead of _Obj.Grp, you need to use _Obj.getAttribute("Grp").

另外,我看你是不是从ODE隐藏引号引起客户端ID。因此,而不是

Also, I see that you are not enclosing client id in quotes from ode-behind. So instead of

txtCode.Attributes.Add("onchange", "ConstantByCode(this," & DivTitle.ClientID & ");")

您需要说

txtCode.Attributes.Add("onchange", "ConstantByCode(this,'" & DivTitle.ClientID & "');")

请注意单引号(')周围的客户端ID。

Note the single quote(') around the client id.

此外,ConstantByCode js函数似乎正在div元素。因此,你需要添加一行到它从客户端ID转换成实际的DOM。 。即

Further, ConstantByCode js function appears to be taking div element. Hence, you need to add line to it for converting from client id to actual DOM. i.e.

function ConstantByCode(_Obj, _Div) {
   _Div = document.getElementById(_Div);
   .... // rest of the code