0

我对我认为是 ASP.NET 页面的 AJAX AutoComplete 扩展器有疑问。

基本上我有一个表单,用户可以在其中输入各种信息。这是FOD输入表。此 FOD 输入表单上的输入框之一是选择一个组织 - 这有一个相应的超链接,单击该超链接会将它们带到搜索表单以选择一个组织。

对于这个搜索表单,我使用的是 UpdatePanels 和 AutoExtenders。因此,用户可以开始输入组织代码或组织名称,AJAX AutoExtender 将在他们输入时显示一个下拉列表,其中显示可能的组织代码和名称。
如果他们点击“Enter”并输入他们想要的组织的部分条目或完整条目,则会显示一个超链接,其中包含每个可能的组织代码、名称和地址。然后,他们可以单击所需组织的链接,它将返回到 FOD 输入表单,其中组织框填充了他们从组织搜索表单中选择的数据。

但是,问题是如果他们没有点击“Enter”,而是使用鼠标从下拉列表中选择一个名称,则包含他们需要填充 FOD 表单的信息的超链接将不会显示。到目前为止,我还无法弄清楚这一点,并且想知道这是否是我在 AJAX 控件中所做的事情。任何帮助我将不胜感激!

谢谢!

下面是正在讨论的部分的代码(OrganizationSearch.aspx):

<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:TextBox ID="OrganizationName" runat="server" AutoPostBack="true" 
                    OnTextChanged="GetCompleteList" Width="420px" />
                <asp:AutoCompleteExtender 
                    ID="AutoCompleteExtender1" 
                    TargetControlID="OrganizationName" 
                    runat="server"
                    ServiceMethod="getNames"
                    CompletionInterval="500"
                    minimumprefixLength="1"
                    completionsetcount="5"
                    />
            </ContentTemplate>
        </asp:UpdatePanel>
                                </td>
                            </tr>
                            <tr>
                            <td colspan="2">
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView 
                id="GridView1" 
                runat="server"
                AutoGenerateColumns="false" Width="700px"
                >
                <Columns>
                    <asp:TemplateField HeaderText="Select the organization from the list below:">
                      <ItemTemplate>
                        <%#"<a href='javascript:setParentName(" + Eval("OrganizationID").ToString() + ",&#039;" + Eval("Organization").ToString() + "&#039;);'>" + Eval("Organization").ToString() + "</a>"%>
                      </ItemTemplate>
                    </asp:TemplateField>

                </Columns>

            </asp:GridView>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="OrganizationName" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>                            
                            </td>

                            </tr>
                        </tbody>
                    </table>
                </div>                    
            </td>
        </tr>
        <tr class="primarylight" style="MIN-HEIGHT: 0.042in">
            <td style="BORDER-BOTTOM: #000000 1pt; BORDER-LEFT: #000000 1pt; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; BORDER-TOP: #000000 1pt; BORDER-RIGHT: #000000 1pt; PADDING-TOP: 1px">
                <h4 align="center" style="FONT-WEIGHT: normal">If you cannot find a particular organization, please contact the help desk via phone (000) 000-0000 or visit the website at: 
                     <a target="_blank" href="helpdeskwebsite" 
                        xd:disableediting="yes"><font size="2">Organizational Help Desk</font></a>&nbsp;The following information is required: Org Code, name, address, and phone number of the organization</h4>
            </td>
        </tr>
        <tr class="primarylight" style="MIN-HEIGHT: 0.042in">
            <td style="BORDER-BOTTOM: #000000 1pt; BORDER-LEFT: #000000 1pt; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; BORDER-TOP: #000000 1pt; BORDER-RIGHT: #000000 1pt; PADDING-TOP: 1px" align="center">

            </td>
        </tr>

这是整个页面的代码:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrganizationSearch.aspx.cs" Inherits="PMT30.Layouts.PMT30.OrganizationSearch" %>

<%@ Register Assembly="AjaxControlToolkit, Version=3.5.50508.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    Namespace="AjaxControlToolkit" TagPrefix="asp" %>

 <style type="text/css">

TABLE {
    BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none
}
TABLE {
    FONT-FAMILY: Verdana; FONT-SIZE: 10pt
}
TABLE {
    BEHAVIOR: url (#default#urn::tables/NDTable)
}
.primaryVeryDark {
    BACKGROUND-COLOR: #1e3c7b; COLOR: #ebf0f9
}
TABLE.xdFormLayout TD {
    BEHAVIOR: url(#default#LayoutText)
}
TABLE.xdLayout TD {
    BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none
}
TD {
    BORDER-BOTTOM-COLOR: #517dbf; BORDER-TOP-COLOR: #517dbf; BORDER-RIGHT-COLOR: #517dbf; BORDER-LEFT-COLOR: #517dbf
}
.primaryLight {
    BACKGROUND-COLOR: #ebf0f9; COLOR: black
}
H4 {
    MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; COLOR: #1e3c7b
}
.xdRepeating {
    DISPLAY: inline-block; BEHAVIOR: url(#default#RepeatingItemUI) url(#default#DataBindingUI)
}
.xdSection {
    BORDER-BOTTOM: #ffffff 1pt solid; BORDER-LEFT: #ffffff 1pt solid; PADDING-BOTTOM: 1px; MARGIN: 6px 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 1px; BORDER-TOP: #ffffff 1pt solid; BORDER-RIGHT: #ffffff 1pt solid; PADDING-TOP: 1px
}
.xdTextBox {
    BORDER-BOTTOM: #dcdcdc 1pt solid; TEXT-ALIGN: left; BORDER-LEFT: #dcdcdc 1pt solid; PADDING-BOTTOM: 1px; BACKGROUND-COLOR: window; MARGIN: 1px; PADDING-LEFT: 1px; TEXT-OVERFLOW: ellipsis; PADDING-RIGHT: 1px; DISPLAY: inline-block; WORD-WRAP: normal; WHITE-SPACE: nowrap; COLOR: windowtext; OVERFLOW: hidden; BORDER-TOP: #dcdcdc 1pt solid; BORDER-RIGHT: #dcdcdc 1pt solid; PADDING-TOP: 1px; BEHAVIOR: url(#default#DataBindingUI)
}
.xdAspTextBox {
    BORDER-BOTTOM: #dcdcdc 1pt solid; TEXT-ALIGN: left; BORDER-LEFT: #dcdcdc 1pt solid; PADDING-BOTTOM: 1px; BACKGROUND-COLOR: window; MARGIN: 1px; PADDING-LEFT: 1px; TEXT-OVERFLOW: ellipsis; PADDING-RIGHT: 1px; DISPLAY: inline-block; WORD-WRAP: normal; WHITE-SPACE: nowrap; COLOR: windowtext; OVERFLOW: hidden; BORDER-TOP: #dcdcdc 1pt solid; BORDER-RIGHT: #dcdcdc 1pt solid; PADDING-TOP: 1px; BEHAVIOR: url(#default#DataBindingUI)
}
.xdBehavior_Select {
    BEHAVIOR: url(#default#SelectHelper) url(#default#DataBindingUI/Select)
}
.xdComboBox {
    MARGIN: 1px
}
SELECT {
    FONT-FAMILY: Verdana; FONT-SIZE: 10pt
}
.xdXButton {
    FONT-FAMILY: Verdana; BEHAVIOR: url(#default#DataBindingUI)
}
.xdBehavior_Boolean {
    BEHAVIOR: url(#default#BooleanHelper) url(#default#DataBindingUI)
}
.xdDTPicker {
    BORDER-BOTTOM: #dcdcdc 1pt solid; BORDER-LEFT: #dcdcdc 1pt solid; BACKGROUND-COLOR: window; TEXT-INDENT: 0px; MARGIN: 1px 1px 2px; DISPLAY: inline; COLOR: windowtext; OVERFLOW: hidden; BORDER-TOP: #dcdcdc 1pt solid; BORDER-RIGHT: #dcdcdc 1pt solid; BEHAVIOR: url(#default#DataBindingUI)
}
.xdDTText {
    PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; WHITE-SPACE: nowrap; HEIGHT: 100%; OVERFLOW: hidden; MARGIN-RIGHT: 22px; PADDING-TOP: 0px
}
.xdBehavior_FormattingNoBUI {
    BEHAVIOR: url(#default#Formatting)
}
.xdDTButton {
    WIDTH: 20px; HEIGHT: 18px; MARGIN-LEFT: -21px; BEHAVIOR: url(#default#DTPicker)
}
.xdRichTextBox {
    BORDER-BOTTOM: #dcdcdc 1pt solid; TEXT-ALIGN: left; BORDER-LEFT: #dcdcdc 1pt solid; PADDING-BOTTOM: 1px; OVERFLOW-X: hidden; BACKGROUND-COLOR: window; FONT-STYLE: normal; MARGIN: 1px; PADDING-LEFT: 1px; TEXT-OVERFLOW: ellipsis; PADDING-RIGHT: 1px; DISPLAY: inline-block; WORD-WRAP: break-word; COLOR: windowtext; VERTICAL-ALIGN: baseline; BORDER-TOP: #dcdcdc 1pt solid; FONT-WEIGHT: normal; BORDER-RIGHT: #dcdcdc 1pt solid; TEXT-DECORATION: none; PADDING-TOP: 1px; BEHAVIOR: url(#default#DataBindingUI)
}
.xdBehavior_Formatting {
    BEHAVIOR: url(#default#Formatting) url(#default#DataBindingUI)
}
TABLE.msoUcTable TD {
    BORDER-BOTTOM: 1pt solid; BORDER-LEFT: 1pt solid; BORDER-TOP: 1pt solid; BORDER-RIGHT: 1pt solid
}
.xdRepeatingTable {
    BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-COLLAPSE: collapse; WORD-WRAP: break-word; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BEHAVIOR: url(#default#urn::tables/NDTable) url(#default#RepeatingItemUI) url(#default#DataBindingUI)
}
.xdTableHeader {
    BACKGROUND-COLOR: #ebf0f9; COLOR: black
}
.xdRepeatingTable TD {
    VERTICAL-ALIGN: top
}
     .style1
     {
         color: #FF0000;
     }
     .style2
     {
         width: 183px;
     }
     .style3
     {
         width: 81px;
     }
     .style4
     {
         width: 15px;
     }
     .style5
     {
         width: 182px;
     }
 </style>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Organization Selection</title>

    <script language="javascript" type="text/javascript">
        var Prefix = "FODForm_TabContainer1_TabPanelRI_RI_";
        var PrefixPI = "FODForm_TabContainer1_TabPanelPI_PI_";
        var PrefixPT = "FODForm_TabContainer1_TabPanelPT_PT_";
        var PrefixFI = "FODForm_TabContainer1_TabPanelFI_FI_";
        var PrefixIC = "FODForm_TabContainer1_TabPanelIC_IC_";
        var PrefixPSI = "FODForm_TabContainer1_TabPanelPSI_PSI_";

        function setParentName(FOD, fName) {

            var organization = opener.document.getElementById(Prefix + "txtOrganization");
            var organizationid = opener.document.getElementById(Prefix + "txtOrganizationID");
            if (organization) {
                organization.value = fName;
                organizationid.value = FOD;
                //opener.document.getElementById(Prefix + "txtOrganization").value = fName;
                //opener.document.getElementById(Prefix + "txtOrganizationID").value = FOD;

            }
            else {
                organization = opener.document.getElementById("CtrInfoForm_txtOrganization");
                organizationid = opener.document.getElementById("CtrInfoForm_txtOrganizationID");
                organization.value = fName;
                organizationid.value = FOD;
            }
            self.close();

        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePartialRendering="true">

        </asp:ToolkitScriptManager>    
<div style="width: 767px" >
    <table table border="1" class="xdFormLayout xdLayout" 
    style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; WIDTH: 765px; BORDER-COLLAPSE: collapse; WORD-WRAP: break-word; BORDER-TOP-STYLE: none; TABLE-LAYOUT: fixed; BORDER-LEFT-STYLE: none" 
    tabindex="-1">
    <colgroup>
        <col style="WIDTH: 754px" />
    </colgroup>

         <tr class="primaryVeryDark" style="MIN-HEIGHT: 27px">
            <td style="BORDER-BOTTOM: #000000 1pt solid; BORDER-LEFT: #000000 1pt solid; BORDER-TOP: #000000 1pt solid; BORDER-RIGHT: #000000 1pt solid">
                <div align="center">
                    <font size="4">Search/Select Organization</font></div>
            </td>
        </tr>
        <tr class="primarylight" style="MIN-HEIGHT: 0.042in">
            <td style="BORDER-BOTTOM: 5pt solid; TEXT-ALIGN: left; BORDER-LEFT: #517dbf 1pt solid; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; BORDER-TOP: #517dbf 1pt solid; BORDER-RIGHT: #517dbf 1pt solid; PADDING-TOP: 1px">

               <div align="center">
                    <table border="1" bordercolor="buttontext" class="xdLayout" 
                        style="border-style: none; border-color: inherit; border-width: medium; WIDTH: 640px; BORDER-COLLAPSE: collapse; WORD-WRAP: break-word; TABLE-LAYOUT: fixed; " 
                        tabindex="-1">
                        <colgroup>
                            <col style="WIDTH: 100px" />
                            <col style="WIDTH: 250px" />
                        </colgroup>
                        <tbody valign="top">            
                            <tr style="MIN-HEIGHT: 27px">
                                <td style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; PADDING-TOP: 1px">
                                    <asp:Label ID="lblOrganization" runat="server" Text="Enter name to search:" Font-Bold="True" 
                                        Font-Names="Verdana" ForeColor="#1E3C7B" Width="170px"></asp:Label>
                                </td>
                                <td>
<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:TextBox ID="OrganizationName" runat="server" AutoPostBack="true" 
                    OnTextChanged="GetCompleteList" Width="420px" />
                <asp:AutoCompleteExtender 
                    ID="AutoCompleteExtender1" 
                    TargetControlID="OrganizationName" 
                    runat="server"
                    ServiceMethod="getNames"
                    CompletionInterval="500"
                    minimumprefixLength="1"
                    completionsetcount="5"
                    />
            </ContentTemplate>
        </asp:UpdatePanel>
                                </td>
                            </tr>
                            <tr>
                            <td colspan="2">
        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:GridView 
                id="GridView1" 
                runat="server"
                AutoGenerateColumns="false" Width="700px"
                >
                <Columns>
                    <asp:TemplateField HeaderText="Select the organization from the list below:">
                      <ItemTemplate>
                        <%#"<a href='javascript:setParentName(" + Eval("OrganizationID").ToString() + ",&#039;" + Eval("Organization").ToString() + "&#039;);'>" + Eval("Organization").ToString() + "</a>"%>
                      </ItemTemplate>
                    </asp:TemplateField>

                </Columns>

            </asp:GridView>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="OrganizationName" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>                            
                            </td>

                            </tr>
                        </tbody>
                    </table>
                </div>                    
            </td>
        </tr>
        <tr class="primarylight" style="MIN-HEIGHT: 0.042in">
            <td style="BORDER-BOTTOM: #000000 1pt; BORDER-LEFT: #000000 1pt; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; BORDER-TOP: #000000 1pt; BORDER-RIGHT: #000000 1pt; PADDING-TOP: 1px">
                <h4 align="center" style="FONT-WEIGHT: normal">If you cannot find a particular organization, please contact the help desk via phone (000) 000-0000 or visit the website at: 
                     <a target="_blank" href="helpdeskwebsite" 
                        xd:disableediting="yes"><font size="2">Organizational Help Desk</font></a>&nbsp;The following information is required: Org Code, name, address, and phone number of the organization</h4>
            </td>
        </tr>
        <tr class="primarylight" style="MIN-HEIGHT: 0.042in">
            <td style="BORDER-BOTTOM: #000000 1pt; BORDER-LEFT: #000000 1pt; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; VERTICAL-ALIGN: middle; BORDER-TOP: #000000 1pt; BORDER-RIGHT: #000000 1pt; PADDING-TOP: 1px" align="center">

            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
    </table>    

</div>    
    </form>
</body>
</html>

这是检索数据的代码(OrganizationSearch.aspx.cs):

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using IDE_Utility.DBConnection;

namespace ORG40.Layouts.ORG40
{
    public partial class OrganizationSearch : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GetCompleteList(object sender, EventArgs e)
        {

            DataSet DS = new DataSet();

            SqlParameter sqlParamComp = new SqlParameter();
            sqlParamComp.ParameterName = "@oName";
            sqlParamComp.DbType = DbType.String;
            sqlParamComp.Value = "%" + OrganizationName.Text + "%";

            SqlParameter[] sqlParams = new SqlParameter[]{
                new SqlParameter("@orgCode", DBNull.Value),                
                sqlParamComp
            };

            DS = DBConnection.GetDataSet("getL_Organization", CommandType.StoredProcedure, sqlParams);
            GridView1.DataSource = DS;
            GridView1.DataBind();



        }
        [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static string[] getNames(string prefixText, int count)
        {
            DataSet DS = new DataSet();
            SqlParameter sqlParamComp = new SqlParameter();
            sqlParamComp.ParameterName = "@oName";
            sqlParamComp.DbType = DbType.String;
            sqlParamComp.Value = "%" + prefixText + "%";

            SqlParameter[] sqlParams = new SqlParameter[]{
                new SqlParameter("@orgCode", DBNull.Value),                
                sqlParamComp
            };

            DS = DBConnection.GetDataSet("getL_Organization", CommandType.StoredProcedure, sqlParams);


            DataTable Dt = new DataTable();
            Dt = DS.Tables[0].DefaultView.ToTable(true, new string[] {"OrgCode", "Name"});
            DataRow[] Dr = new DataRow[Dt.Rows.Count];
            Dt.Rows.CopyTo(Dr, 0);
            return Array.ConvertAll(Dr, new Converter<DataRow, String>(DataRowToString));

        }

        public static string DataRowToString(DataRow pDr)
        {
            return (Convert.ToString(pDr["OrgCode"]) + ": " + Convert.ToString(pDr["Name"]));
        }
    }
}
4

1 回答 1

1

啊,很抱歉这个很长而且不准确的帖子。这个问题在我的存储过程中没有发布代码。在参数中不正确地考虑分号。

于 2013-06-17T18:38:20.093 回答