我的弹出容器中有4个字段,第二个字段的AutoPostBack为true,因此当最初尝试在TextBox中键入内容时,未单击方法(GetSearchStudentName)。如果我选择了第二个字段,然后尝试在TextBox中键入它,则可以正常工作。我该如何解决这个问题?
在StudentTrip.ascx中,
<!--Add a Student for Trip Starts here -->
<div class="form1 popup-container" runat="server">
<div class="formAddNewRequest" id="addNewRequestTrip" runat="server">
<div class="messages">
<h1 class="AddTripFormHeading" style="text-align:center">Add New Trip Request</h1>
<asp:ImageButton ID="ImageButton3" class="close-popup" runat="server" ImageUrl="~/Image/close.png" />
</div>
<div class="information_text">
<label class="required"><span class="mandatory">*</span>Required Fields</label>
</div>
<div class="subdiv number">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<cc1:AutoCompleteExtender ServiceMethod="GetSearchStudentName" MinimumPrefixLength="1" CompletionInterval="10"
EnableCaching="false" CompletionSetCount="10" TargetControlID="txtUserName" ID="AutoCompleteExtender1"
runat="server" FirstRowSelected="false" >
</cc1:AutoCompleteExtender>
<label class="lbl_Name">Student User Name<span class="mandatory">*</span></label>
<asp:TextBox class="txt_boxs" runat="server" ID="txtStdName"></asp:TextBox>
<%--<asp:RequiredFieldValidator class="errorfield" ValidationGroup='GrpVal' ID="empUserName" runat="server" ControlToValidate="txtUserName"
ErrorMessage="Enter UserName" ForeColor="Red" Font-Size="Small"></asp:RequiredFieldValidator>--%>
</div>
<div class="subdiv">
<label class="lbl_Name">Destination<span class="mandatory">*</span></label>
<asp:DropDownList class="status" ID="AddDestination" runat="server" OnSelectedIndexChanged="DropDownRequestTime" AutoPostBack="true" >
<%-- <asp:ListItem Selected="True">Select</asp:ListItem>--%>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Choose Destination" ForeColor="Red" InitialValue="0" ControlToValidate="AddDestination" ValidationGroup="GrpVal"></asp:RequiredFieldValidator>
</div>
<div class="subdiv">
<label class="lbl_Name">Trip Time<span class="mandatory">*</span></label>
<asp:DropDownList class="status" ID="AddTripTime" runat="server" OnSelectedIndexChanged="DropDownRequestEnroute" AutoPostBack="true">
<%-- <asp:ListItem Selected="True">Select</asp:ListItem>--%>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Choose Trip Time" ForeColor="Red" InitialValue="0" ControlToValidate="AddTripTime" ValidationGroup="GrpVal"></asp:RequiredFieldValidator>
</div>
<div class="subdiv">
<label class="lbl_Name">Drop Point<span class="mandatory">*</span></label>
<asp:DropDownList class="status" ID="AddDropPoint" runat="server" AutoPostBack="false" >
<%-- <asp:ListItem Selected="True">Select</asp:ListItem>--%>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Choose Drop Point" ForeColor="Red" InitialValue="0" ControlToValidate="AddDropPoint" ValidationGroup="GrpVal"></asp:RequiredFieldValidator>
</div>
<div style="margin-left:40px;">
<asp:Button ID="Save_Trip_Id" class="ava-btn primary-btn" CssClass="AddTripFormAddButton" runat="server" Text="Submit" OnClick="addNewUserTrip_Click" ValidationGroup="GrpVal" />
<asp:Button ID="Cancel_Trip_Id" class="ava-btn secondary-btn" CssClass="AddTripFormCancelButton" runat="server" Text="Cancel" />
</div>
</div>
</div>
<!--Add a Student for Trip Ends here -->
在StudentTrip.aspx页面中,
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetSearchStudentName(string prefixText)
{
DataTable Result = new DataTable();
string str = "Select StudentName from StudentDetails where StudentName like '" + prefixText + "' + '%'";
da = new SqlDataAdapter(str, con);
dt = new DataTable();
da.Fill(dt);
List<string> Output = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
Output.Add(dt.Rows[i][0].ToString());
return Output;
}
我期望的是,最初我尝试键入名称时,应该点击该方法并在AutoCompleteTextBox中检索该名称。