PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了我如何在asp.net网站中实现SOTag文本框大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

大家好,我想在asp.net网站中使用SOTag文本框(此处为link,SOTag文本框).
PHP示例是这样的:

<!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>

我的aspx页面是这样的:

<%@ 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>

然后我在js / so_tag.js中进行了更改

autocomplete_URL: 'SOTag.PHP'

autocomplete_URL: 'MyPage.cs'

现在我不明白如何在C#中实现result.PHP和SOtag.PHP.有人可以帮我吗?
真诚的
廷沃

编辑1

我已经按照您的解释做了,但是没有用.

在web.config中,我写道

<urlMappings enabled="true">
    <add url="~/Index.aspx" mappedUrl="~/SoTag.ashx" /> 
  </urlMappings>

但是在index.aspx中,结果是json字符串.

我已经在MEGA上上传了项目示例->在这里您可以找到link
提前致谢,
廷沃

解决方法:

要使其在asp.net上运行,您需要执行一些步骤.

>设置自动完成处理程序.
>更改so_tag.js以询问新处理程序.
>将其附加到任何asp.net页面.

处理程序

您如何做到的.创建一个处理程序SoTag.ashx,然后在其中返回jSon格式的标签.这只是一个简单的返回,以查看返回格式.

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);   
}

代码上,在此文件上,您必须打开数据库,获取q查询字符串,向数据库询问

> ID
>标签
> tag_description

以json格式返回它们,然后插件显示它们.

更改so_tag.js

在so_tag上,找到autocomplete_URL,然后更改为asp.net处理程序,如下所示:

autocomplete_URL:“ SoTag.ashx”,

asp.net页面

最简单的就是将它附加到任何输入控件上.

<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>

最后

唯一的困难是完成处理程序以从数据库读取数据,您需要添加很多标签信息,然后以json格式返回它们.

代码已通过测试并且可以正常工作,下面是屏幕截图:

http://www.planethost.gr/so/SoTags.gif

小改进

SO_tag.js每次按键都调用太多,最好留出一些时间来完成键入操作,因此请在键盘绑定中添加使用/更改此代码.

    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);
    });

大佬总结

以上是大佬教程为你收集整理的我如何在asp.net网站中实现SOTag文本框全部内容,希望文章能够帮你解决我如何在asp.net网站中实现SOTag文本框所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: