0

I am using jQuery UI widget Tag it. Code which i am using is working fine but all the Tag values visible on the browser.

Code I am using is below

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
      <script src="../JavaScript/tag-it.js"></script>
    <link href="../CSS/tagit.ui-zendesk.css" rel="stylesheet" />
    <link href="../CSS/jquery.tagit.css" rel="stylesheet" />
    <script>
        $(function(){
           var sampleTags = [<%# this.SuggestionList %>];
            //var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
            $('#myTags').tagit();         
            $('#singleFieldTags').tagit({
                availableTags: sampleTags,            
                allowSpaces: true,
                singleFieldNode: $('#mySingleField')
            });
           });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="content">
            <p>              
                <input name="tags" id="mySingleField" value="Apple, Orange" disabled="true">
            </p>
            <ul id="singleFieldTags"></ul>
    </div> 
    </form>
</body>

Code behind

string queryString = "select * from SIB_KWD_Library ORDER BY Keyword asc";

    using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["vConnString"].ToString()))
    {

        using (SqlCommand command = new SqlCommand(queryString, connection))
        {

            connection.Open();

            using (SqlDataReader reader = command.ExecuteReader())
            {

                while (reader.Read())
                {

                    if (string.IsNullOrEmpty(SuggestionList))
                    {
                        SuggestionList += "\'" + reader["Keyword"].ToString() + "\'";
                    }
                    else
                    {
                        SuggestionList += ", \'" + reader["Keyword"].ToString() + "\'";
                    }

                }
            }
        }
    }

In browser source code all the tag keywords are visible. Something like

var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];

Please suggest any other way to do this.

Thanks in advance :)

8
  • 2
    What problem you are facing? Commented Apr 30, 2015 at 10:11
  • @Adil all the keywords are visible in browser source code. I want to hide this.and no. of keyword is up to 1 million. Commented Apr 30, 2015 at 10:14
  • In browser source code all the tag keywords are visible.....Yes because you are using them up...restrict it if you dont want to use them all Commented Apr 30, 2015 at 10:29
  • 1
    select * from SIB_KWD_Library ORDER BY Keyword asc ,Put some where,or top clause here Commented Apr 30, 2015 at 10:30
  • @ShekharPankaj thats why i post the question. for the suggetion for how do I hide these keywords , is any other way ? Commented Apr 30, 2015 at 10:31

1 Answer 1

3
+50

Use <%= this.SuggestionList %> instead of <%# this.SuggestionList %>

JS:-

 <script>
        $(function(){
           var sampleTags = [<%= this.SuggestionList %>];
            //var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
            $('#myTags').tagit();         
            $('#singleFieldTags').tagit({
                availableTags: sampleTags,            
                allowSpaces: true,
                singleFieldNode: $('#mySingleField')
            });
           });
    </script>

Edit

JS:-

<script>
    $(function () {
        $.ajax({
            url: "http://"+location.host + '/Default.aspx/GetKeywords',
            type: 'GET',
            datatype: "json",
            contentType: "application/json; charset=utf-8",
            success: function(res) {
                $('#singleFieldTags').tagit({
                    availableTags: res.d,
                    allowSpaces: true,
                    singleFieldNode: $('#mySingleField')
                });
            },
            failure: function(err) {
                alert(err);
            }
        });
    });

</script>

CS:-

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public static string[] GetKeywords()
    {
        List<string> lst = new List<string>();
        string queryString = "select * from SIB_KWD_Library ORDER BY Keyword asc";
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["vConnString"].ToString()))
        {
            using (SqlCommand command = new SqlCommand(queryString, connection))
            {
                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {

                    while (reader.Read())
                    {
                        lst.Add(reader["Keyword"].ToString());
                    }
                }
            }
        }
        return lst.ToArray();
    }

Simply replace the lst with your keywords returned from database.

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

12 Comments

That is okay but my query is not like you answered :(
@Gitz Write a ajax method to get the list from the server using WebMethod and inside success use your tagit code.
@wix kid that is what i am looking for. Actually from direct call from code behind is easy but all the keywords are visible into the browser source code. i want to bind it directly from sql sever
@Gitz Please see Edit in my answer.
Okay !! i am trying :) i will let you know
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.