I am trying to get the AjaxControlToolkit (ACT) Auto complete extender working.
It was working briefly but has now stopped working and I can't figure out why. I haven't changed changed anything in my project that I can see would affect this.
I have even created a brand new VS2013 project and tried to implement this but still no joy.
I see several references to "ajaxToolkit:ToolkitScriptManager" but I cannot find a reference for this anywhere. I have tried installing the toolkit from a download as well as via NUGET and it simply will not work.
I have tried every example on here, at least 20 of them or more and still not joy. If you have it working please post your code because mine doesn't work and its pointless posting it be cause i have tried absolutely everything suggested here
Any help would be much appreciated as I really dont want to engineer something unelegant to get around this.
Thanks loads
[UPDATE]
ToolkitScriptManager is removed from ACT 15.1 see here So that answers this question but the autocomplete still is not working
[UPDATE]
Here is an example I put togetgher, which still does not work with or without the [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] directive
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TestWebSite.WebForm1" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetCompletionList"
MinimumPrefixLength="1"
CompletionInterval="100"
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="TextBox1"></cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TestWebSite
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] s = {"a","b","c","d"};
return s;
}
}
}
You need to register the AJAX Control Toolkit Library by putting the following line just below the #PageDirective
this is the ajaxtoolkit
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
then this is the example to call ajaxtoolkit
<cc1:toolkitYouWantToUse/>
thasts it
Ok I have it working. I created a brand new test projects in VS2013. I used the developer features of Google Chrome to debug and saw I was constantly getting a 500 error. In my experience I've usually caused this by getting my web addresses wrong so that led me to checking that the web service was working. (See further down)
After fixing that problem and knowing that the web service was OK I engaged in some trial and error, and the steps below solved the problem. I now have the AutoCompleteExtender working in all my projects using this same method.
(This may not be the way to do it but I know it works for me)
Remove the nuget installed version of the AjaxControlToolkit (ACT)
Manually add the reference to the ACT dll that I had downloaded, get the latest version from here.
Add a .asmx file to your project with the WebMethod defined as below. You can actually call the method any name you like the profile (e.g. parameters and return type) must remain the same. There may be other variations but I don't know what they are. I just know that this configuration worked for me.
Re-add the AutoCompleteControl. the VS IDE will add the #Register directive for you
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetCompletionList"
ServicePath="WebService1.asmx"
MinimumPrefixLength="0"
CompletionInterval="100"
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="TextBox1"></cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace TestWebSite
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)//, string contextKey)
{
string[] s = { "a", "b", "c", "d" };
return s;
}
}
}
//List<string> works just as well as string[]
Run the project, manually navigate to the .asmx page and make sure that the function returns the results you expect. VS knows your running in debug so will let you add parameters and call the web method.
Related
I have a web site in windows host = https://blobloblo/WebForm5.aspx
When run that link on FireFox developer & take a look at Console logs,
I will see this error :
Error: ASP.NET Ajax client-side framework failed to
Because of this error many parts of this web site do n't work correctly.
Yesterdays every thing was ok.
But today they closed the host for some hours & did some updates such as plesk's update.
After running the host again this error appeared.
What should i tell them to fix this problem?
WebForm5 ASPX :
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="Virtual_Visa_Cards.WebForm5" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" Height="26px" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
WebForm5 C# :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Virtual_Visa_Cards
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "This is Ajax Call = CallBack";
}
}
}
Related Topic :
ASP.NET Ajax client-side framework failed to load. when put the ScriptManager on a blank page
I test all answers in the topic upper WITH NO RESULT.
In plesk i went to Web Application Firewall & put Web application firewall mode to off.
I worked one day to solve this issue.
When I just copy (without deploying) an aspx page with code-behind to a web site I get a Parser Error Message when I try to use the page.
Let us assume this is just for testing purposes that I want to develop a single page in Visual Studio then copy (or FTP) it to a web site.
The complete error message is:
Parser Error Message: Could not load type 'SimpleSite.WebForm2'.
The WebForm2.aspx file is:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="SimpleSite.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
The WebForm2.aspx.cs file is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SimpleSite
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = TextBox1.Text;
}
}
}
I am not sure if the namespace is the problem, it appears to be. I have used Expression Web to create an ASP.Net file with code-behind that I can just FTP
but that does not have a namespace (yes, I know; it is in the global namespace).
If I want to make one or two aspx files with code-behind just for educational purposes to be copied without deploying, can I do that using a Visual Studio Web Project or Web Site and maintain the page such that it still works as a page in the Visual Studio Web Project or Web Site?
Yes, the namespace is a problem.
Visual Studio creates pages for a Web Site without a namespace specified, in other words it creates pages with the code in the global namespace. Therefore simple pages (that do not use additional files) created in a VS Web Site can be copied individually by copying just the aspx file and corresponding aspx.cs file.
Another difference between a Web Project and a Web Site is that VS adds a aspx.designer.cs file for each page. It is not created for Web Sites.
I've been doing some really clever stuff (I think) in ASP.Net c#, so much so that the simple stuff is more difficult (if that makes sense)
I have this snippet of code in my page
<form id="form1" runat="server">
<asp:HiddenField runat="server" ID="hdnConfirm" value="Hello World" />
<asp:LinkButton runat="server" PostBackUrl="/confirm.aspx" Text="Confirm">
</asp:LinkButton>
</form>
I have this snippet of code in confirm.aspx.
if !(IsPostback)
{
lblConfirm.Text = Request.Form["hdnConfirm"]
}
I was expecting this to be nice and simple but when i click the button and go to page "confirm.aspx" the Request.Form has no values. What have I missed ?
[TESTING]
I ran a test on a brand new web forms project in VS2013. Dot.Net 4.5.1 This does not work. PreviouPage is always null. Whether surrounded by (!IsPostBack) or not. Doesn't matter if the submitting control is a Button, LinkButton or Hyperlink. Request.Form["hdn"] is also null. I have restarted my computer just in case and still no joy. I am missing something really simple I am sure of it but I can't see what
This is the first page nothing in the code behind
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton runat="server" PostBackUrl="~/WebForm2.aspx">click</asp:LinkButton>
<asp:HiddenField runat="server" ID="hdn" Value="3" />
</div>
</form>
</body>
</html>
This is the second page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string s = ((HiddenField)this.PreviousPage.FindControl("hdn")).Value;
}
}
}
On confirm.aspx use PreviousPage.FindControl instead :
HiddenField hdnFieldName = this.PreviousPage.FindControl("hdnConfirm") as HiddenField;
string hiddenValue = string.Empty;
if (hdnFieldName != null)
{
hiddenValue = hdnFieldName.Value;
}
Here is good example to get you started.
What's going on Here:
By default with VS 2013 and Asp.Net v4.5.1 , there is a feature FriendlyUrls which is enabled.
The FriendlyUrls feature does kind of Asp.Net routing , thus changing URLs from localhost/webform1.aspx to localhost/webfrom1
PostbackUrl property will not work in combination with Asp.Net Routing. When ASP.NET routing is in use the PreviousPage URL is the final routed URL. The runtime will check for a file represented by the Routed URL now, which will be webform1 and NOT webfrom1.aspx. Since there is NO such file as webform1, so it will always set the PreviousPage to null.
Possible Solutions:
So, now you know the issue at hand.
1.) Either don't use the Routing system of Asp.Net Friendly Urls , in this case, therefore try adding the <%# PreviousPageType VirtualPath="~/WebForm1.aspx"%> to webform2.aspx page and check.
2.) OR if you keep the FriendlyURLs and hence the Routing system, make changes in your code to read the Form values using some other alternatives.
I'm new to ASP.NET and C#, I've primarily worked with Java. I want to dynamically add nodes to a tree view. I've followed a few tutorials but whenever I implement them they do not appear to work. I keep getting an error: "The name 'MyTreeView' does not exist in the current context".
Here's the C# code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LocalTest
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MyTreeView.Nodes.Add(new TreeNode("Node1"));
MyTreeView.Nodes[0].ChildNodes.Add(new TreeNode("ChildNode"));
}
}
}
}
And the HTML/ASP:
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="MyTreeView" Runat="server">
</asp:TreeView>
</div>
</form>
</body>
</html>
"MyTreeView" is the ID of the treeview contained in the Default.aspx file.
The few tutorials I have followed seem to access the treeview directly with its ID as seen above which makes very little sense to me. For instance, if I were to do this in Android I would have to use the findViewById and establish a link between the XML and the Object.
Does anyone have any suggestions? I've bumbled around this site for a bit and I'veonly found similar issues but I cannot get a clear answer.
Thank you.
Looking at the code above, you are using what's known as ASP.Net WebForms where there are "server side" controls (e.g. <asp:TreeView ID="MyTreeView" Runat="server">)
The "page" (html aspx) needs to somehow "wire itself" to the code (c# file). It will need a "server-side" directive like so:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFormsApplication.WebForm1" %>
<!DOCTYPE html>
//...the rest of the html goes here plus web controls, etc.
At which point, you can see stuff like Inherits="WebFormsApplication.WebForm1" that maps to the Class:
namespace WebFormsApplication
{
public partial class WebForm1 : System.Web.UI.Page
....
found in the WebForm1.aspx.cs file, also in the directive CodeBehind="WebForm1.aspx.cs"
So voila :)
establish a link between the XML and the Object.
Hth...
You do not have TreeView control in default.aspx. It is in .html file and default.aspx.cs can not see TreeView control.
It seems you are missing Page directive in your asp.net page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
Hope someone can help with this. I've been up and down the web and through this site looking for an answer, but still can't get the Autocomplete AJAX control to work. I've gone from trying to include it in an existing site to stripping it right back to a very basic form and it's still not functioning. I'm having a little more luck using Page Methods rather than a local webservice, so here is my code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="droptest.aspx.cs" Inherits="droptest" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="1" ServiceMethod="getResults"
TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Services;
using System.Web.Services;
public partial class droptest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public string[] getResults(string prefixText, int count)
{
string[] test = new string[5] { "One", "Two", "Three", "Four", "Five" };
return test;
}
}
Tried to keep things as simple as possible, but all I get is either the autocomplete dropdown with the source of the page (starting with the <! doctype...) letter by letter, or in IE7 it just says "UNDEFINED" all the way down the list.
I'm using Visual Web Developer 2008 at the moment, this is running on Localhost. I think I've exhausted all the "Try this..." options I can find, everything from adding in [ScriptMethod] to changing things in Web.Config.
Is there anything obviously wrong with this code?
Only other thing that may be having an effect is in Global.asax I do a Context.RewritePath to rewrite URLs - does this have any effect on AJAX?
Thanks for any help you can give.
You also need to include your page name as the servicePath, I think.
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="1" ServiceMethod="getResults" ServicePath="droptest.aspx"
TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
Try adding ServicePath to the cc1:AutoCompleteExtender with the path to the web service.
[WebMethod, ScriptMethod]
public string[] getResults(string prefixText, int count)
{
be sure to include the ScriptMethod attribute.
Right, something I've added in from these suggestions has worked!!! Still have a problem though, it works in a standalone project but adding it back into the existing project and it's not working again. So thanks for the help so far, I have a working example, just have to figure out what is killing it inside the other project now.
Make the method static:
[WebMethod]
public static string[] getResults(string prefixText, int count)
{
string[] test = new string[5] { "One", "Two", "Three", "Four", "Five" };
return test;
}
Update:
A shot in the dark... try moving the ScriptManager above the textbox. Also, I would set the ServicePath to "~/" simply because you mention the URL rewrites.
If you are using IIS 5.1, try to temporarily remove .* from the application setting. This wildcard setting prevents AJAX like control to work correctly.
In my case, my project use rewrite rule to remove the extension aspx. I thing the problem is that. I comment the rewrite rule in web.config. Then clear solution. Rebuild it. Clear all history in firefox / chrome (what you use). Then Ctrl+F5 or F5. Autocomplete show correctly.