将Javascript与ASP.Net同步 [英] Sync Javascript with ASP.Net

查看:68
本文介绍了将Javascript与ASP.Net同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有< asp:label id =" lblPrice" RUNAT = QUOT;服务器" />通过引用对象ID使用Javascript在客户端更新

的标签

_ctl0_lblPrice。


Javascript做客户端 - 计算取决于用户在网络表单上选择的
选项。


我遇到的问题是ASP.Net看起来不像了解任何关于

Javascript在回发时所做的更改。


我的问题是:如何让ASP.Net知道最新的客户端

更新到lblPrice而不必在服务器端复制客户端

计算?


请告知示例这对我来说是一个新的领域。请

注意我可以通过Javascript来修改ASP.Net对象,但我无法获得

ASP.Net来查看Javascript对这些对象所做的任何更新。

让Javascript在请求对象中将更新发布回ASP.net

击败了我正在寻找的目的。我需要有ASP.Net

检测Javascript对< asp:label>所做的最新更新对象。


Aladdin Nassar

解决方案

>我需要有ASP.Net

检测Javascript对< asp:label>所做的最新更新对象。




javascript无法操纵asp:标签。该标签在

客户端不存在。 AFAIK,javascript更新服务器端的唯一方法是使用javascript或者将数据发回服务器,或者将
javascript写入可以写入的字段然后通过表格

提交回来。


-Darrel


javascript无法操纵asp:标签。标签不存在于客户端。




实际上,我做到了。只需将_ctl0_添加到asp:标签ID并在javascript 中插入




GetObject(''_ ctl0_lblPrice' ').innerText =''Hello There'';


其中lblPrice是asp:label'的ID。


和GetObject是一个Javascript函数,它只是在

DOM中找到该对象而不管浏览器如何:


------------- -------------------------------------------------- --------------

< script LANGUAGE =" Javascript">

<! -


if(top.location!= self.location){top.location = self.location;} //

退出框架浏览

function onerror(){return(true);} // true关闭错误

消息


var isDHTML = 0;

var isLayers = 0;

var isAll = 0;

var isID = 0;


if(document。 getElementById){

isID = 1; isDHTML = 1;

} else {

if(document.all){

isAll = 1; isDHTML = 1;

} else {

browserVersion = parseInt(navigator.appVersion);

if((navigator.appName.indexOf(' 'Netscape'')!= -1)&&(browserVersion

== 4)){

isLayers = 1; isDHTML = 1;

}

}

}


函数GetObject(objectID){

if(isID){return(document.getElementById(objectID));}

if(isAll){return(document.all [objectID]);}

if(isLayers){return(document.layers [objectID]);}

返回null;

}


// - >

< / script>

-------------------- -------------------------------------------------- -------


我的问题仍然存在。如何让ASP.Net看到Javascript对lblPrice对象所做的更新
更新。在上面的

示例中,Javascript将lblPrice值更改为Hello There。我怎么用
让ASP.Net看到服务器端的变化?


Aladdin Nassar


>实际上,我做到了。只需在_ctl0_前加上asp:标签ID,然后在你的javascript 中插入



GetObject(''_ ctl0_lblPrice'')。innerText =''你好'';

其中lblPrice是asp:label'的ID。


客户端没有asp:标签。它不是HTML标签。这是一个

ASP.net标签。它会在发送到

浏览器之前在服务器上解析。

我的问题仍然存在。如何让ASP.Net看到Javascript对lblPrice对象所做的更新。


我的答案仍然存在。让它回发或写入表单字段。

在上面的例子中,Javascript将lblPrice值更改为''Hello There''。



它什么也没做。在浏览器中加载页面后,它只是在HTML中重写了一些文本。


-Darrel



I have an <asp:label id="lblPrice" runat="server"/> tag that I update
on the client side using Javascript by referring to the object ID
_ctl0_lblPrice.

The Javascript does client-side calculations depending on the user''s
selections of choices on the web form.

The problem I have is that ASP.Net does not seem to know anything about
the changes made by Javascript upon postback.

My question is: how do I get ASP.Net to know the latest client-side
updates to lblPrice without having to duplicate the client-side
calculations on the server side ?

Please advise with examples as this is new territory for me. Please
note I can get Javascript to modify ASP.Net objects, but I cannot get
ASP.Net to see any updates Javascript has made to these objects.
Having Javascript post the updates back to ASP.net in a request object
defeats the purpose of what I am looking for. I need to have ASP.Net
detect the latest updates Javascript made to the <asp:label> object.

Aladdin Nassar

解决方案

> I need to have ASP.Net

detect the latest updates Javascript made to the <asp:label> object.



javascript can''t manipulate an asp:label. The label doesn''t exist on the
client side. AFAIK, the only way to have javascript update server side is to
have the javascript either post the data back to the server, or have
javascript write to a field that can then be sent back upon a form
submission.

-Darrel


javascript can''t manipulate an asp:label. The label doesn''t
exist on the client side.



Actually, I did. Just prepend a _ctl0_ to asp:label ID and insert the
following in your javascript:

GetObject(''_ctl0_lblPrice'').innerText=''Hello There'';

where lblPrice is the asp:label''s ID.

And GetObject is a Javascript Function that simply finds that object in
DOM irrespective of the browser like:

-----------------------------------------------------------------------------
<script LANGUAGE="Javascript">
<!--

if (top.location != self.location){top.location = self.location;} //
get out of framed browsing
function onerror(){return(true);} // true turns off error
messages

var isDHTML = 0;
var isLayers = 0;
var isAll = 0;
var isID = 0;

if (document.getElementById){
isID = 1; isDHTML = 1;
}else{
if(document.all){
isAll = 1; isDHTML = 1;
}else{
browserVersion = parseInt(navigator.appVersion);
if((navigator.appName.indexOf(''Netscape'') != -1) && (browserVersion
== 4)){
isLayers = 1; isDHTML = 1;
}
}
}

function GetObject(objectID){
if(isID){return(document.getElementById(objectID)) ;}
if(isAll){return(document.all[objectID]);}
if(isLayers){return (document.layers[objectID]);}
return null;
}

//-->
</script>
-----------------------------------------------------------------------------

My question still remains please. How do I get ASP.Net to see the
updates that Javascript made to the lblPrice object. In the above
example, Javascript changed lblPrice value to ''Hello There''. How do I
get ASP.Net to see that change on the server side ?

Aladdin Nassar


> Actually, I did. Just prepend a _ctl0_ to asp:label ID and insert the

following in your javascript:

GetObject(''_ctl0_lblPrice'').innerText=''Hello There'';

where lblPrice is the asp:label''s ID.
There is NO asp:label on the client side. It''s not an HTML tag. It''s an
ASP.net tag. It gets parsed on the server before it is ever sent to the
browser.
My question still remains please. How do I get ASP.Net to see the
updates that Javascript made to the lblPrice object.
My answer still remains. Have it postback or write to a form field.
In the above
example, Javascript changed lblPrice value to ''Hello There''.



It did nothing of the sort. It simply rewrote some text in the HTML after
the page loaded in the browser.

-Darrel


这篇关于将Javascript与ASP.Net同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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