Click here to Skip to main content
11,577,673 members (40,613 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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.
Posted 22-Mar-13 14:23pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//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
}
  Permalink  
Comments
Motley Drew at 22-Mar-13 21:12pm
   
I actually tried this. In the "Do your thing" spot, I put, getSong(). I get,
"An object reference is required for the non-static field, method or property 'SiteMaster.getSong()'"
S. M. Ahasan Habib at 22-Mar-13 22:15pm
   
Seems you write the serverside method in the Masterpage. You must write it to Page codebehind. Event if you write that webmethod to the user control then it will not work. So you just create a page, then take ScriptMangager referenece to that page(either you do not take reference it from masterpage) then call webmethod which is written in that page code behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 180
1 OriginalGriff 115
2 Richard MacCutchan 100
3 Peter Leow 100
4 Abhinav S 100
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100