I am trying to use SOTag textbox in a asp.net website(Here link of SOTag textbox).
The php example is this:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SOTag</title>
<style type="text/css">
body {
padding:30px;
width:960px;
margin:0 auto;
}
pre {
border:#ccc 1px solid;
background:#EFEFEF;
padding:10px;
}
</style>
<link rel="stylesheet" type="text/css" href="css/so_tag.css?<?php echo rand(0,1000); ?>">
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/so_tag.js?<?php echo rand(0,1000); ?>"></script>
</head>
<body>
<h2>jQuery.SO_Tag</h2>
<p>First a little description about what this plugin is for. This plugin is designed to be used with a backend database full of tags, not to be able to tag whatever you or the user wants to. I may add that feature if people want to but you cannot currently let your users add custom tags using this plugin</p>
<p>It's easy to get started, first include the JavaScript files and the CSS</p>
<pre>
<?php echo htmlentities('<link rel="stylesheet" type="text/css" href="css/so_tag.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/so_tag.js"></script>'); ?>
</pre>
<br />
<pre>
<?php echo htmlentities('<form action="result.php" method="post">
<input type="text" value="3_php" name="single_example" id="single_example" />
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
$(\'#single_example\').sotag({
description : true
});
</script>'); ?>
</pre>
<br />
<p><strong>Here is an example with multiple tag fields</strong></p>
<form action="result.php" method="post">
<p>Programming words (example: PHP)</p>
<input type="text" value="" name="multi_example_programming_tags" class="multi_example_programming_tags" />
<br />
</form>
<script type="text/javascript">
$('.multi_example_programming_tags').sotag({
description : true
});
</script>
</body>
</html>
My aspx page is this:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="js/so_tag.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/so_tag.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Example</title>
</head>
<body>
<form id="form1" runat="server" method="post">
<input type="text" value="" name="multi_example_programming_tags" class="multi_example_programming_tags" />
<br />
</form>
<script type="text/javascript">
$('.multi_example_programming_tags').sotag({
description: true
});
</script>
</body>
</html>
Then I've changed in js/so_tag.js
autocomplete_URL: 'SOTag.php'
with
autocomplete_URL: 'MyPage.cs'
Now I don't understand how to implement result.php and SOtag.php in c#. Someone could help me?
EDIT1
I have done what you have explained but it dosen't work.
In web.config I wrote
<urlMappings enabled="true">
<add url="~/Index.aspx" mappedUrl="~/SoTag.ashx" />
</urlMappings>
But in the index.aspx the result is the json string.
I have upload the project example on MEGA--> here you can find the link .
To make it work on asp.net you need to follow some steps.
so_tag.js
to ask the new handler.How you make it. You create a handler SoTag.ashx
, and there you return on jSon format the tags. Here is just a simple return to see the return format.
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
// Simple one TAG format SO_Tag, and one more for test
string cRet = @"
[{
""id"": 10,
""tag"": ""SO_Tag"",
""tag_description"": ""SO_Tag: Tagging system based on StackOverflows tag search""
},{
""id"": 11,
""tag"": ""asp.net"",
""tag_description"": ""ASP.NET is a web application framework developed by Microsoft to allow programmers to build dynamic web sites and web applications.""
}]";
context.Response.Write(cRet);
}
On your code, on this file you must open your database, get the q
query string, ask your database for the
return them on json format, and the plugin shows them.
On the so_tag, find the autocomplete_URL, and change to the asp.net handler, as:
autocomplete_URL: 'SoTag.ashx',
And the most simple, just attach it to any input control.
<head runat="server">
<script type="text/javascript" src="jquery.min.js"></script>
<link rel="stylesheet" href="so_tag.css" type="text/css" />
<script type="text/javascript" src="so_tag.js"></script>
<script type="text/javascript">
jQuery( document ).ready(function()
{
jQuery('#<%=txtSoTags.ClientID%>').sotag({
description : true
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txtSoTags" Width="300">1_some, 2_example, 3_tags</asp:TextBox>
</form>
</body>
</html>
The only difficulty here is to complete the handler to read data, from your database, that you need to add a lot of informations of the tags, and return them back with json format.
This code here is tested and work, and here is the screenshot:
(source: planethost.gr )
The SO_tag.js
is make too many calls on every key press, is better to give some time to finish the typing, so add use/change this code on the keyup
bind.
var cKeyPressTimer = null;
// Now if the user starts typing show results
elem.bind('keyup', function(e)
{
if(cKeyPressTimer)
clearTimeout(cKeyPressTimer);
cKeyPressTimer = setTimeout(SO_update_results, 500);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.