从javascript调用VB.net函数

时间:2022-04-09 15:59:15

I need to find a way to call a vb.net function in my aspx page from javascript. I have a Jquery function that makes the .drop class .droppable, and whenever I drop a .draggable onto a drop target, my Jquery code successfully fires a java alert statement. All in pure javascript. What I need to do is some heavy math!

我需要找到一种方法从javascript中调用我的aspx页面中的vb.net函数。我有一个Jquery函数,它生成.drop类.droppable,每当我将.draggable放到drop目标上时,我的Jquery代码就会成功触发java alert语句。所有在纯JavaScript中。我需要做的是一些繁重的数学!

I do understand that javascript exists client-side, ASP/VB exists server-side, and never the two shall meet. From google research, it seems like the ideal way to get what I need done, is to trigger an asynchronous postback in my update panel. I created a hidden button called "HiddenButton", and I also created a hidden label called "HiddenLabel". How do I get it to work so when I drop something, my javascript calls something that updates both the text in the HiddenLabel (so I can pass a value to server-side), and somehow fire the HiddenButton_click event?

我明白javascript存在于客户端,ASP / VB存在于服务器端,而且两者都不会相遇。从谷歌研究来看,似乎是获得我需要完成的工作的理想方式,就是在我的更新面板中触发异步回发。我创建了一个名为“HiddenButton”的隐藏按钮,我还创建了一个名为“HiddenLabel”的隐藏标签。我如何让它工作,所以当我放弃一些东西时,我的javascript调用一些东西来更新HiddenLabel中的文本(所以我可以将值传递给服务器端),并以某种方式触发HiddenButton_click事件?

My current javascript goodness looks like this:

我目前的javascript善良看起来像这样:

<script type="text/javascript">  
  $(document).ready(function() {  
doReady();  

var prm = Sys.WebForms.PageRequestManager.getInstance();  
prm.add_endRequest(function(s, e) {  
    doReady();  
});  
});

function doReady() {

$('.drag').draggable({ revert: true, helper: 'clone' });
$('.drop').droppable({
    tolerance: "touch", // Here should be a string
    drop: function() { alert('dropped'); }

This is where I think something needs to go to update the label and trigger the post-back, but I don't know what it is :(

这是我认为需要更新标签并触发回发的地方,但我不知道它是什么:(

});

} // End of do ready
</script>

2 个解决方案

#1


You can use the hidden variable's OnValueChanged event. Wire up that event, change the value of the hidden variable, and write this statement -

您可以使用隐藏变量的OnValueChanged事件。连接该事件,更改隐藏变量的值,并写下此语句 -

__doPostBack('<%= hdnHidden.UniqueID  %>', ''); //This statement will fire the OnValueChanged event and the control will be moved to the server side where you can update the label and do your processing.

#2


Calling __doPostBack with your JS causes a page postback.

使用JS调用__doPostBack会导致页面回发。

function __doPostBack(eventTarget, eventArgument) { ... }

#1


You can use the hidden variable's OnValueChanged event. Wire up that event, change the value of the hidden variable, and write this statement -

您可以使用隐藏变量的OnValueChanged事件。连接该事件,更改隐藏变量的值,并写下此语句 -

__doPostBack('<%= hdnHidden.UniqueID  %>', ''); //This statement will fire the OnValueChanged event and the control will be moved to the server side where you can update the label and do your processing.

#2


Calling __doPostBack with your JS causes a page postback.

使用JS调用__doPostBack会导致页面回发。

function __doPostBack(eventTarget, eventArgument) { ... }