4

i am working on asp.net c#. I want to send a string value from c# to ascx page . I am using following code to do that ,

string one = @"\'" + names[0, 0] + "\'" + "," + @"\'" + names[1, 0] + "\'";
string[] splitted = one.Split('\'');
string onces =  splitted[1] + ","  + splitted[3] ;
inpHide.Value =onces;

In ascx page i should pass this values to javascript , i did like this ,

$(document).ready(function () {
  var hiddenControl = '<%= inpHide.ClientID %>';
  var values = document.getElementById(hiddenControl).value;
  alert(values);

  var tweetUsers = [values];
});
<input id="inpHide" type="hidden" runat="server" />

when i debug javascript using firebug values coming like [""twitter","microsoft""] but " quotes are being added automatically into javascript . but i should get like this ["twitter","microsoft"] because of this string javascript is not working. how can i solve this problem ? please help me to solve this problem . thank you in advance.

1
  • the value is a string, not an array. You need to convert your string into an array. Try using .split() like this: var tweetUsers = values.split(/,/); (It's not a good solution though) Commented Aug 29, 2012 at 6:04

1 Answer 1

1

you should try using JSON, and pass that string to client side: use this function to serialize your string into JSON:

    public string ToJSON(this object obj)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(obj);
    }

and then pass the return string to your client-side, try using a public string and in javascript use that public string instead of hidden control

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.