how tp pass array to javascript function
can anybody plz tell me hw to pass an array from cs file to javascript function in source file in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Mar 7, 2011, 2:17 PM
Suthish NairPosted Mar 5, 2011, 7:25 AM
Sam HobbsPosted Mar 4, 2011, 1:00 PM
Raja KrishnamurthyPosted Mar 4, 2011, 11:09 AM
so can u suggest hw to call dis function in pageload event of cs page.actually m calling it like dis bt its nt doing anything.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "", false);
I see two problems with the code.
1. For the Slide() function to work you got to use RegisterStartupScriptBlock (renders the JS at the end of the page) rather than using ClientScriptBlock;
2. You cannot just use var path = document.getElementById("HiddenField1.ClientID").value; if you want to use HiddenField1's client ID. Your statement checks for the exact ID HiddenField1.ClientID which I think is not what you want. Its been a while since I worked in ASP .Net web forms but I think you got to use document.getElementById("<%=HiddenField1.ClientID%>").value;
Finally I dont know what your function slide() does??
Hope this helps.
Happy Progamming!!!
Regards,
Raja
Eric FrazinPosted Mar 4, 2011, 10:16 AM
I may be wrong about this does "this.Page.ClientScript.RegisterStartupScript" handle this already?
Here is the code to finish the process.
//Start Code:
private void SaveToFile(string FilePath) {
System.Text.StringBuilder Build = new System.Text.StringBuilder();
System.IO.TextWriter Save = new System.IO.StreamWriter(FilePath);
Save.Write(Build.ToString());
Save.Flush();
Save.Close();
}
private void ButtonSave_Click(object sender, EventArgs e) {
try
{
SaveToFile("JSTEST.html");
}
catch
{
}
}
//End Code!!!!!
I am primarily a VB programmer, fairly new to C# so please correct any mistakes you may find, as this code is untested. - BrÜ
Amit ChoudharyPosted Mar 4, 2011, 4:08 AM
your question and what you have asked by giving example both are vice versa of eachother.. so you should be clear to your problem first, otherwise you'll get confuse and at last will find no exact solution..
Identifying the problem will ensure the way to the solution and reduce your time and effort.
:)
swati agrawalPosted Mar 4, 2011, 3:00 AM
Suthish NairPosted Mar 4, 2011, 2:46 AM
Sam HobbsPosted Mar 4, 2011, 2:43 AM
swati agrawalPosted Mar 4, 2011, 2:31 AM
so can u suggest hw to call dis function in pageload event of cs page.actually m calling it like dis bt its nt doing anything.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "", false);
Soft CornerPosted Mar 4, 2011, 1:41 AM
Take This Example of How can u pass ArrayList To JavaScript function
Jaganathan BantheswaranPosted Mar 4, 2011, 1:21 AM
you can try this.
Amit ChoudharyPosted Mar 4, 2011, 1:17 AM
I don't know if there's such method out-there.. to pass variables value to javascript.
well i have another idea to achieve this.. add an hidden field to your page assign the value of the array by adding all values comma separated. and then retreive the value from this hidden field through javascript and use Split() function to convert it back to an array.
for e.g.,
string[] arr={asb,aba,aas};
use loop to make this array as comma separated string. then assign that string as hidden field value.
string arrstring="asb,aba,aas";
HiddenField1.value=arrstring;
now in your aspx page retrieve the value using javascript.
string comsep=document.getElementById('<%HiddenField.ClientID%>');
var arr=comsep.Split(',');
This solution is only for 1 dimensional array.
Hope this helps you.
Please don't forget to mark "Do you like this answer" if it helps you.
Thanks.