AJAX AutocompleteExtender isn't working. Web Service works - web-services

This is c# .net 2.0. I am using a masterpage.
The WebService works fine on its own.
I am completely stumped. When I type in the TextBox, nothing happens.
Files:
EditTicket.aspx
AutoComplete.asmx
App_Code/AutoComplete.cs
EditTicket.aspx:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<asp:ScriptManager id="ScriptManager1" runat="server" EnablepageMethods="true">
<Services>
<asp:ServiceReference Path="AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<cc2:AutoCompleteExtender
runat="server"
ID="AutoCompleteExtender1"
ServicePath="AutoComplete.asmx"
ServiceMethod="AutoComplete2"
MinimumPrefixLength="1"
CompletionSetCount="12"
TargetControlID="TextBox3"
EnableCaching="True" >
</cc2:AutoCompleteExtender>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
AutoComplete.asmx:
<%# WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %>
AutoComplete.cs:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod]
public string[] AutoComplete2(string prefixText,int count)
{
string conString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
SqlConnection connection = new SqlConnection(conString);
connection.Open();
SqlParameter prm;
string sql = "Select program_name FROM CM_Programs WHERE program_name LIKE #prefixText";
SqlDataAdapter cmd = new SqlDataAdapter(sql, connection);
prm = new SqlParameter("#prefixText", SqlDbType.VarChar, 50);
prm.Value = prefixText+ "%";
cmd.SelectCommand.Parameters.Add(prm);
DataTable dt = new DataTable();
cmd.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["program_name"].ToString(),i);
i++;
}
connection.Close();
return items;
}
}

"Nothing happens" is not an easy description to go on. When you say nothing happens, have you checked that
The server code is being hit for the
web service?
Your query is being executed and
returning results?
Your items array is being populated
correctly?
If "nothing" is that none of the above is happening, I would start checking that there are no javascript errors on the page and that your AutoComplete extender is rendering correctly (examine the page controls in a trace).

Try fiddling with the CompletionInterval property. I have used this control in the past and wasn't seeing the behavior I expected until I set the CompletionInterval to a much lower value. It defaults to 1000 (ms), I would give it a shot with a value of 1, just to see if everything is working as it should (and womp's steps should help to narrow down where the communication issues are happening) and if it does work, keep increasing the value until you hit a value that makes sense (1 ms sends a lot of requests to the server). Report back on what works and what doesn't.

Related

Unit Testing ODataQueryOptions Gives MissingMethodException DependencyInjection

So here is my problem, I have an OData Web Api service that uses ODataQueryOptions to filter data from our sql server and I am trying to setup a .Net Framework Unit Test project to test the controllers with different query options. I have been searching for several days now and found many examples but most of them use an older version of OData. This example is the best one I have found so far, the only problem is that calling config.EnableDependencyInjection(); gives me the following exception:
Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
Here is an example of my code:
using System.Collections.Generic;
using System.Web.Http.Results;
using System.Web.OData;
using System.Web.OData.Query;
using System.Net.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using University.API.OData.Controllers;
using University.API.OData.Models;
using System.Web.OData.Routing;
using System.Web.Http;
using System.Web.OData.Extensions;
[TestClass]
public class SalesforceUnitTest
{
private HttpRequestMessage request;
private ODataQueryOptions<Product> _options;
[TestInitialize]
public void TestInitialize()
{
request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/product?$top=5");
var model = WebApiConfig.GetModel();
HttpConfiguration config = new HttpConfiguration();
config.EnableDependencyInjection(); //Throws Missing Method Exception
WebApiConfig.Register(config);
config.EnsureInitialized();
request.SetConfiguration(config);
ODataQueryContext context = new ODataQueryContext(
model,
typeof(Product),
new ODataPath(
new Microsoft.OData.UriParser.EntitySetSegment(
model.EntityContainer.FindEntitySet("product"))
)
);
_options = new ODataQueryOptions<Product>(context, request);
}
[TestMethod]
public void ProductTest()
{
var controller = new ProductController();
controller.Request = request;
var response = controller.Get(_options);
var contentResult = response as OkNegotiatedContentResult<List<Product>>;
Assert.IsNotNull(contentResult);
Assert.IsNotNull(contentResult.Content);
}
}
Let me know if there is any other information you may need.
Thank you for any help you can provide.
EDIT:
Here what is referenced in the unit test project:
EntityFramework
EntityFramework.SqlServer
Microsoft.Data.Edm
Microsoft.Data.OData
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.DependencyInjection.Abstractions
Microsoft.OData.Core
Microsoft.Odata.Edb
Microsoft.Spatial
Microsoft.Threading.Tasks
Microsoft.Threading.Tasks.Extensions
Microsoft.Threading.Tasks.Extensions.Desktop
Microsoft.VisualStudio.TestPlatform.TestFramework
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions
System
System.ComponentModel.DataAnnotations
System.Net
System.Net.Http
System.Net.Http.Extensions
System.Net.Http.Primitives
System.Net.Http.WebRequest.
System.Spatial
System.Web
System.Web.Http
System.Web.OData
ODataAPI
I figured it out after some more digging. It seems that my Unit Test project was using a different version than my ODataApi project. This for some weird reason was causing the MissingMethodException instead of a VersionMismatchException. Hopefully this helps someone else who is looking into why Dependency Injection isnt working for your Unit Test project.

Sending Data to Soap Service by SharePoint 2013 or SPD2013

I have a SOAP service that takes a USERID and a Qualification Code and returns a Boolean(true) if the User was found and the Qualification Code was added to their name. Inside Visual Studio I had no problem writing a simple page that had 2 text boxes where I took the info from those text boxes and submitted it to the web service. I can't figure out how to do this inside SharePoint or SharePoint Designer both are 2013. I have followed these directions to add the service as a Data source but I'm unsure how to work with it.
The overall project is I have a training site and when an employee passes a test I want to pass the user and qualification to the SOAP web service to be updated in another environment. Yes it's duplicated info but it's how the company wants it. The information in SharePoint is stored in a list.
Edit
So I think I have to do it in ParameterBindings. If I just change the location to Controls(textboxid) I'm assuming this will call the web service with whatever is in these text boxes but so far it's not.
<parameterbindings>
<ParameterBinding Name="userID" Location="Control(UserIDTB)" DefaultValue="domain\user"/>
<ParameterBinding Name="qualificationCode" Location="Control(QualCode)" DefaultValue="PIT"/>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
<ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
<ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/>
</parameterbindings>
So for me I couldn't figure out or maybe it's not possible to do this in SharePoint Designer. I had to create an Event Receiver inside Visual Studio that connects to SOAP service then sends Data from my list to that service. The completed code is below. I doubt I need all the additions at the top but I just left them as it was working.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
namespace CompletedTraining.TrainingCompleteListener
{
/// <summary>
/// List Item Events
/// </summary>
public class TrainingCompleteListener : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
//Item was just added to the list
base.ItemAdded(properties);
using (SPWeb web = properties.OpenWeb())
{
try
{
//get the item that was just added
SPListItem currentItem = properties.ListItem;
//create a new connection to the NavSoapService
NAVSoapService.EmployeeQualificationMgt service = new NAVSoapService.EmployeeQualificationMgt();
//Use the default credentials for this service
service.Credentials = CredentialCache.DefaultCredentials;
//convert the Name field from the list to a string we'll use to pass to the NavSoapService. We need the username(superb\user) instead of just name(first last) the next 3 lines do this conversion
string nameField = currentItem["Name"].ToString();
SPFieldUserValue userField = (SPFieldUserValue)currentItem.Fields["Name"].GetFieldValue(nameField);
SPUser user = userField.User;
//Once we have user id we need to get their login name(superb\user) and remove the 7 junk characters to the left
string loginName = (user.LoginName).Substring(7);
//Call the service with the login name and the Qualification code store the result in the result variable.
bool result = service.AddEmployeeQualification(loginName, (string)currentItem["Qualification Code"]);
//write the result in the Uploaded to NAV column
currentItem["Uploaded to NAV"] = result;
//update the current item in the list.
currentItem.Update();
}
catch (Exception ex)
{
throw ex;
}
}
}
}
}
Two other items needed and 1 is in your project you need to connect to the Web Service and 2 is to change the Elements.xml file if you only want this to have an affect on 1 list.
<!--<Receivers ListTemplateId="100">-->
<Receivers ListUrl="Lists/Completed Training">

Autoroute Bulk operations in Orchard

If you customize an autoroute part you have the option to recreate the url on each save.
The help text under this option says:
"Automatically regenerate when editing content
This option will cause the Url to automatically be regenerated when you edit existing content and publish it again, otherwise it will always keep the old route, or you have to perform bulk update in the Autoroute admin."
I have digged all around but I cannot find anywhere an "Autoroute admin".
Is it really there?
It was a proposed feature never implemented?
Any idea to do a bulk update even without an Admin page?
Thanks
EDIT after #joshb suggestion...
I have tried to implement a bulk operation in my controller.
var MyContents = _contentManager.Query<MyContentPart, MyContentPartRecord>().List().ToList();
foreach (var MyContent in MyContents) {
var autoroutePart = recipe.ContentItem.As<AutoroutePart>();
autoroutePart.UseCustomPattern = false;
autoroutePart.DisplayAlias = _autorouteService.GenerateAlias(autoroutePart);
_contentManager.Publish(autoroutePart.ContentItem);
}
In this way it recreates all aliases for the types that contain the given part MyContentPart.
With some more work this code can be encapsulated in a command or in a new tab in Alias UI.
After finished the current project I'm doing I will try that...
You could create a module and implement a command that does a bulk update. Shouldn't be too much work if you're comfortable creating modules. You'll need to implement DefaultOrchardCommandHandler and inject IContentManager to get all the parts you're interested in.
Enable Alias UI in the modules section will give you the admin section for managing routes, however I'm not sure what kind of bulk updates it offers
Publishing the ContentItem will do nothing if it is already Published (as it was in my case).
Instead, one could call the PublishAlias method on the AutorouteService. I ended up with a Controller, something like this:
using Orchard;
using Orchard.Autoroute.Models;
using Orchard.Autoroute.Services;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Security;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace MyNamespace.MyModule.Controllers {
public class AutorouteBulkUpdateController : Controller {
private readonly IOrchardServices _orchardServices;
private readonly IAutorouteService _autorouteService;
private Localizer T { get; set; }
public AutorouteBulkUpdateController(IOrchardServices orchardServices, IAutorouteService autorouteService) {
_orchardServices = orchardServices;
_autorouteService = autorouteService;
T = NullLocalizer.Instance;
}
public ActionResult Index() {
if (!_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings"))) {
return new HttpUnauthorizedResult();
}
int count = 0;
IEnumerable<AutoroutePart> contents;
do {
//contents = _orchardServices.ContentManager.Query<AutoroutePart>(VersionOptions.Latest, new string[] { "Page" }).Slice(count * 100, 100).ToList();
contents = _orchardServices.ContentManager.Query<AutoroutePart>(VersionOptions.Latest).Slice(count * 100, 100).ToList();
foreach (var autoroutePart in contents) {
var alias = _autorouteService.GenerateAlias(autoroutePart);
if (autoroutePart.DisplayAlias != alias) {
autoroutePart.UseCustomPattern = false;
autoroutePart.DisplayAlias = alias;
_autorouteService.PublishAlias(autoroutePart);
}
}
_orchardServices.TransactionManager.RequireNew();
_orchardServices.ContentManager.Clear();
count += 1;
} while (contents.Any());
return null;
}
}
}

Crystal Report 2011 Report/SQL Server 2008/ASPX Issues

I have a webserver configured with ColdFusion 10. Within an application I have built in ColdFusion, I want to deploy a Crystal Report that requires a parameter that the user would enter. I built the report in Crystal Reports 2011. The report works within the Designer.
I then used Recrystallize to generate the ASPX, ASPX.VB, and Web.config pages that go with the report.
I had to adjust the IIS settings to accommodate the fact that ColdFusion requires the enabling of 32 bit applications and the Crystal Reports components require the disabling of 32 bit applications by putting the Crystal Report and pages in their own folder, converting them to an application and setting that application to a different Application Pool than the ColdFusion application.
The report viewer initially opened with the prompt for the parameter that the report was built on. When you entered the parameter and clicked OK, the report would error with a dialog of: Failed to open the connection. Failed to open the connection. [with the report name].
I am not sure where to begin troubleshooting this.
Any help that you can provide would be greatly appreciated.
this is aspx file.....
<asp:UpdatePanel ID="updpnlReport" runat="server">
<ContentTemplate>
<CR:CrystalReportViewer ID="crvAccountReportParameter" runat="server"
oninit="crvAccountReportParameter_Init"
EnableParameterPrompt="False" HasToggleParameterPanelButton = "false" HasCrystalLogo ="False"/>
</ContentTemplate>
</asp:UpdatePanel>
This is .cs fie..........
protected void btnSubmit_Click(object sender, EventArgs e)
{
LoadData();
}
protected void LoadData()
{
string pstrType;
pstrType = Request.QueryString["Type"];
string strCompanyName = objSession.SelCompanyName;
string strBranchName = objSession.SelBranchName;
string strHeading = "";
DataSet dsData = null;
dsData = objAccountReportBAL.getAccountRegister(Convert.ToInt16(objSession.FyId), int.MinValue, long.MinValue, Convert.ToDateTime(RadDtpFromDate.SelectedDate), Convert.ToDateTime(RadDtpToDate.SelectedDate), pstrType);
dsData.Tables[0].TableName = "Account_Trn_v";
if (pstrType == "JV")
{
strHeading = "Journal Voucher Register Report";
rptDoc.Load(Server.MapPath("~/ReportCrystal/Account/Detail/GeneralVoucharRegister.rpt"));
}
rptDoc.SetDataSource(dsData.Tables[0]);
rptDoc.SetParameterValue("#CompanyName", objSession.SelCompanyName);
rptDoc.SetParameterValue("#BranchName", objSession.SelBranchName);
rptDoc.SetParameterValue("#Heading", strHeading);
rptDoc.SetParameterValue("#Stdate", RadDtpFromDate.SelectedDate);
rptDoc.SetParameterValue("#EnDate", RadDtpToDate.SelectedDate);
crvAccountReportParameter.ReportSource = rptDoc;
crvAccountReportParameter.DataBind();
}

Testing nhibernate Castle Windsor mappings in httpModules is not registered

I want to write test that verifies mappings in castle windsor.
I am using ASP MVC2 where i am using castle windsor to map my repositories.
I have read this article:
http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx
and based on this i have created my MS Test
[TestMethod()]
public void GetContainerTest()
{
MooseMvc.Infrastructure.DependencyInjectionInitialiser target = new MooseMvc.Infrastructure.DependencyInjectionInitialiser(); // TODO: Initialize to an appropriate value
IWindsorContainer container = target.GetContainer();
foreach (IHandler assignableHandler in container.Kernel.GetAssignableHandlers(typeof(object)))
{
container.Resolve(assignableHandler.ComponentModel.Service);
}
}
The data for target.getcontainer() implements
this._windsorContainer.Register(Component.For<TInterfaceType>()
.ImplementedBy(typeof(TConcreteType)).LifeStyle.PerWebRequest);
I get message as follows:
Looks like you forgot to register the http module
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add
name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,
Castle.Windsor" />' to the <httpModules> section on your web.config.
If you're running IIS7 in Integrated Mode you will need to add it to
<modules> section under <system.webServer>
I have had the same problem and I have found a solution: You can define an event in the contructor of the unit test to override the LifestyleType.
void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
{
if (model.LifestyleType == LifestyleType.Undefined)
model.LifestyleType = LifestyleType.Transient;
if (model.LifestyleType == LifestyleType.PerWebRequest)
model.LifestyleType = LifestyleType.Transient;
}
public UnitTest1()
{
containerWithControllers = new WindsorContainer();
containerWithControllers.Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated);
}
i have found beautifull guide
http://docs.castleproject.org/Windsor.Windsor-tutorial-part-three-a-testing-your-first-installer.ashx
there is not much else to add..