Click here to Skip to main content
15,905,590 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I want to do like that.there is a playlist database table in mysql database.it has title,artist,mp3 url column.
I want to take these urls from code behind from database and will send javascript file so dynamically will be.

my javascript file like that

C#
var myPlaylist = [

    {
        mp3:'http://3.s3.envato.com/files/10407161/preview.mp3', hereeeeeeee
        oga:'music/5.ogg',
        title:'Missing You', hereeeee
        artist:'Dejans', hereeeeeee
        rating:5,
        buy:'#',
        price:'17',
        duration:'5:25',
        cover:'music/180x180.jpg'
    },
    {
        mp3:'http://3.s3.envato.com/files/54178721/preview.mp3', hereeee
        oga:'music/4.ogg',
        title:'Midnight In Tokyo', hereeeee
        artist:'BlueFoxMusic', hereeeee
        rating:4,
        buy:'#',
        price:'17',
        duration:'2:51',
        cover:'music/180x180.jpg'
    },


I want to send from codebehind mp3:'xxxxxxxx.mp3'
title:'yyyyyy'
to this javascript file
how can I do?
Posted
Comments
Sergey Alexandrovich Kryukov 9-Jul-14 17:38pm    
This is not how it works. Javascript file is loaded when code behind is already finished its job. You need a postback, so you could generate new Javascript with new data.
—SA
Member-2338430 9-Jul-14 17:43pm    
this is Pass C# ASP.NET array to Javascript array topic????? because javascript array
Sergey Alexandrovich Kryukov 9-Jul-14 19:00pm    
You don't "pass" anything; you can only generate appropriate Javascript, with variable content...
—SA
Member-2338430 9-Jul-14 17:47pm    
can I do like that
page load

get datas from database titles artists urlss
protected void Page_Load(object sender, EventArgs e)
{
string[] serverSideArray = { "One", "Two", "Three", };

string arrayString = string.Empty;

for (int i = 0; i < serverSideArray.Length; i++)
{
if (arrayString.Length > 0)
arrayString += ",";

arrayString += string.Format("new String('{0}')", serverSideArray[i]);
}

// arrayString = "new String('One'),new String('Two'), ...etc";
this.ClientScript.RegisterArrayDeclaration("g_clientSideArray", arrayString);
}
Member-2338430 9-Jul-14 17:56pm    
I understood your commends how can update js file inside content???

1 solution

If any one wants to be pass data from code behind to javascript then use WebMethod and PageMethod which normaly working as like core ajax when we have to create webmethod at code behind with return type as writen bellow code:


1. Call Web Method in Javascript using PageMethod technique:

Code Behind Page:
-----------------------------------------------------------
step 1: Create one Web Method in code behind page

[WebMethod]
public static int GetValue()
{
int no=10;
return no;
}

step 2: Create javascript function for call web method using PageMethod technique

function GetCodeBehind_Value()
{
PageMethods.GetValue(onsucess,onerror);
}


// These both method is normally used to handling javascript GetCodeBehind_Value() method which is return result value of "onsucess(result)" method if method is sucessfully called other then return value of "onerror(result)" method.
function onsucess(result)
{
alert(result);
}

function onerror(result)
{
alert(result);
}


Note: Plz use ScriptManage and enamblepageload method true.

XML
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
   </asp:ScriptManager>


I hope it will help you....... :-)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900