在没有PostBack的情况下调用Code Behind函数 [英] Calling Code Behind function without PostBack

查看:91
本文介绍了在没有PostBack的情况下调用Code Behind函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个随机加载歌曲的MP3播放器。我在CodeBehind页面中有一个函数,它运行SQL查询以提取随机记录。我在PageLoad期间调用该函数,它运行良好。我正在尝试添加一个再次调用该函数的按钮,但不刷新页面。我正在使用图像按钮。



我查看了AJAX解决方案,但是从我发现的内容来看,Web方法无法调用我的getNext函数。



我相信我的问题不在于我的代码,而在于我的设计。如果有人有好的想法指出我正确的方向,我将不胜感激。

I am built an mp3 player that loads songs up randomly. I have a function in the CodeBehind page that runs a SQL query to pull a random record. I call the function during the PageLoad, and it works great. I''m trying to add a button that calls the function again, but without refreshing the page. I''m using an image button.

I looked into AJAX solutions, but from what I found, so it the Web Method can''t call my getNext function.

I am fairly confident that my issue does not lie in my code, but in my design. If someone has a good ideas to point me in the right direction, I would be grateful.

推荐答案

//在页面上



< asp:scriptmanager id =ScripManager1runat =serverenablepagemethods =truexmlns:asp =#unknown>



< script>



函数SavePostions(对象){

PageMethods.SavePosition(object.attr(''id'') ,object.position()。left +px,object.position()。top +px,object.css(height),object.css(width),function(){});

}



< / script>









//代码背后





[WebMethod ]

public static void SavePosition(string id,string x,string y,string heght,string width)

{

//你的事情

}
//On Page

<asp:scriptmanager id="ScripManager1" runat="server" enablepagemethods="true" xmlns:asp="#unknown">

<script>

function SavePostions(object) {
PageMethods.SavePosition(object.attr(''id''), object.position().left + "px", object.position().top + "px", object.css("height"), object.css("width"), function () { });
}

</script>




//Code Behind


[WebMethod]
public static void SavePosition(string id, string x, string y, string heght, string width)
{
//Do Your Thing
}


这篇关于在没有PostBack的情况下调用Code Behind函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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