I'm trying to use an auto-complete, and it works fine if I call a function without a parameter in the web service:
<WebMethod()> _
<Script.Services.ScriptMethod()> _
Public Function GetCompanyNames2() As String()
Dim db As New DataClassesDataContext
Dim company = From c In db.CT_Companies
Where c.CompanyName.Contains("Airport")
Select c.CompanyName
Return company.ToArray
End Function
If I try to call a function that takes a parameter, which I need to do so I can get the text entered by the user in the text box, it won't even hit the function at all, I put a break point on it and it never hits the break point:
<WebMethod()> _
<Script.Services.ScriptMethod()> _
Public Function GetCompanyNames(ByVal prefixTest As String) As String()
Dim db As New DataClassesDataContext
Dim company = From c In db.CT_Companies
Where c.CompanyName.Contains(prefixTest)
Select c.CompanyName
Return company.ToArray
End Function
Does anybody know what's going on?
Here is the content from default.aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<div>
<asp:TextBox ID="txtCompanyName" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtCompanyName"
ServicePath="~/AutoComplete.asmx" ServiceMethod="GetCompanyNames" MinimumPrefixLength="1"
EnableCaching="true" />
</div>
Have you tried to rebuild your webservice project and refresh the web reference (the web service proxy) in your web project?
This is probably too long after the fact to be useful but the parameter must be named prefixText and not prefixTest as you have here.
Related
I'm in a web programming class and our current assignment has to be done using ASP.Net. The problem and cause of my frustration is due to my professors lack teaching, unclear directions, and outdated "guide." I'm using the 2012 version of Visual Studio Ultimate.
I'm supposed to make a completely different program than this "guide," but I have no idea how I'm supposed to do so when I have all of these errors/warning doing EXACTLY as his guide shows.
In his poorly written guide.. he states: "Upon debugging a few errors will show up. Fix them and your webpage will display." Yet using his code and following everything as he did.. I have 52 errors and 3 warnings. I searched for most of them on Google and only found Q&A specific questions for other peoples programs.
There's not much code and I don't get how there are so many errors from replicating my professors code/guide. I'll add some of the errors/warning followed by the code from the files below. If someone can help me fix some of these errors, I'd more than greatly appreciate it. Thanks!
3 warnings:
Warning 34 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 26 14 CS316Program5(1)
Warning 50 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 58 14 CS316Program5(1)
Warning 53 Function without an 'As' clause; return type of Object assumed. \\vmware-host\shared folders\Documents\Visual Studio 2012\WebSites\CS316Program5\game.aspx.vb 91 14 CS316Program5(1)
Some of the 52 errors :(
Error 1 'Context' is not a member of 'game'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 128
Error 3 Class 'game_aspx' must implement 'ReadOnly Property IsReusable As Boolean' for interface 'System.Web.IHttpHandler'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 144
Error 4 Class 'game_aspx' must implement 'Sub ProcessRequest(context As HttpContext)' for interface 'System.Web.IHttpHandler'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 144
Error 5 'GetWrappedFileDependencies' is not a member of 'ASP.game_aspx'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 163
Error 6 'Server' is not a member of 'ASP.game_aspx'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 166
Error 7 property 'SupportAutoEvents' cannot be declared 'Overrides' because it does not override a property in a base class. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 169
Error 8 Value of type 'ASP.game_aspx' cannot be converted to 'System.Web.UI.Page'. C:\Users\Justin Geis\AppData\Local\Temp\Temporary ASP.NET Files\root\95a42970\24c7c528\App_Web_mrk1wbiu.0.vb 230
game.aspx
<%# Page Language="VB" AutoEventWireup="false" CodeFile="game.aspx.vb" Inherits="game" Debug="true" %>
<!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>Customer Data</title>
</head>
<body>
<form id="form1" runat="server">
Name:
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ControlToValidate="username" ErrorMessage="name required"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" onClick="nameEntered" runat="server" Text="Submit" />
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<h1>
<asp:Label ID="pageloaded" runat="server" Text=""></asp:Label>
</h1>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" Visible="false">
<ContentTemplate>
<br />
Zip Code:
<asp:TextBox ID="Zip" runat="server" AutoPostBack="true" OnTextChanged="ZipChanged"></asp:TextBox>
<asp:Label ForeColor="Red" ID="errormessage" runat="server" Text=" "> </asp:Label>
<br />
Address:
<asp:TextBox ID="Address" AutoPostBack="true" runat="server"></asp:TextBox>
<asp:Label ForeColor="Red" ID="errormessage2" runat="server" Text=" "> </asp:Label>
<br />
City:
<asp:TextBox ID="City" runat="server"></asp:TextBox>
<br />
State:
<asp:TextBox ID="State" runat="server"></asp:TextBox>
<asp:Label ID="updatemessage" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
game.aspx.vb
' game.aspx.vb
' asp.net vb.net example
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
' code behind is in a class like this
' the name customer must match the name in the inherits
' attribute of the page directive at the top of the aspx file
Partial Class customer
Inherits System.Web.UI.Page
' zipchanged executed when user clicks in address textbox
Function ZipChanged(ByVal sender As Object, ByVal e As System.EventArgs)
' verify that user entered 5 digits for zip code
' using regualr expression pattern matching
Dim myMatch As Match = System.Text.RegularExpressions.Regex.Match(Zip.Text, "^\d{5}$")
' if 5 digits entered
If myMatch.Success Then
errormessage.Text = "" ' blank out any previous error message
updatemessage.Text = "City/State updated at " + DateTime.Now.ToString()
' VB case (select/switch) statement
Select Case Zip.Text ' select on zip code entered
Case "40502"
' update text boxes
City.Text = "Lexington"
State.Text = "KY"
Case "60609"
City.Text = "Chicago"
State.Text = "IL"
Case Else ' entered zip code not found
City.Text = ""
State.Text = ""
updatemessage.Text = "Unknown zip code"
End Select
Else ' invalid zip code entered
errormessage.Text = "zip code must be 5 digits"
City.Text = ""
State.Text = ""
updatemessage.Text = ""
End If
End Function
' Page_Load executed whenever page is loaded by user
Function Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Page.IsPostBack is used to check if this is
' the first load of the page (not an Ajax update)
If Not Page.IsPostBack Then
' first load - not Ajax update of page
Dim I As Integer ' iterator for cookie search
Dim foundcookie As Boolean = False ' flag if cookie found
Dim currenttime As String ' current time kept here
currenttime = DateTime.Now.ToString()
' Running on your local PC cookies kept
' under "localhost". Iterate thru all local cookies.
For I = 0 To Request.Cookies.Count - 1
' If not first execution within 24 hours
' the time was put in a cookie named LastAccess
If Request.Cookies.Item(I).Name = "LastAccess" Then
foundcookie = True
' Get the cookie value and display to user
pageloaded.Text = "Page last loaded at: " + Request.Cookies.Item(I).Value
End If
Next
If Not foundcookie Then
pageloaded.Text = "First load of page at: " + currenttime
End If
' Save current time in a cookie named LastAccess
Dim myCookie As New HttpCookie("LastAccess")
' cookie value
myCookie.Value = currenttime
' cookie expires in 24 hours
myCookie.Expires = DateTime.Now.AddHours(24)
' now add the cookie (name in myCookie: LastAccess)
Response.Cookies.Add(myCookie)
End If ' if not first load of page
End Function
Function nameEntered(ByVal sender As Object, ByVal e As System.EventArgs)
Button1.Text = "Clicked"
UpdatePanel1.Visible = True
End Function
End Class
Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<appSettings>
<add key="webpages:Enabled" value="true"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
There's some code missing here, among other things.
The code-behind class - game.aspx.vb - is referenced in the page declaration at the top of game.aspx: -
CodeFile="game.aspx.vb" Inherits="game"
But the class in game.aspx.vb is called customer ? This won't work. The 'inherits' part of the page declaration clearly states it is looking for a class called 'game'.
Also, a bunch of your errors are related to an IHttpHandler implementation: -
Error 3 Class 'game_aspx' must implement 'ReadOnly Property IsReusable As Boolean' for interface 'System.Web.IHttpHandler'... (snip)
Apparently, these are in a class called game_aspx which is not in anything you posted.
Your lecturer is trying to get you to solve stupid and confusing problems before you have seen how things work properly. This is an idiotic way of teaching, especially when he is showing you a whole load of concepts you probably haven't seen before.
I feel sorry for you. Nobody should have to suffer such poor quality teaching.
Anyway - if you can dig out the rest of the code and post it, I might be able to help.
I have to admit to start that I am relatively new to ASP.NET and shamefully have not really used server tags on the client side page yet. I have a repeater on my page that iterates through the rows of a datatable and shows a hyperlink object for each item using the below tag:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/DiseaseInfo/Syndrome.aspx?SyndromeID=<%# Eval('SYNDROME_ID')%>&SpeciesID=<%# Eval('SPECIES_ID')%>" Text='<%# Eval("SYNDROME_NAME").ToString%>'></asp:HyperLink>
The problem that I am having is that the server doesn't render out the <%# %> tags. If I put this same link into an tag then it works just fine. I am sure that it has to do with the fact that the hyperlink is already being rendered on the server-side, but I can't figure out how to change things to get it to work correctly. Any help would be greatly appreciated.
Reverse the order of your single / double quotes.
<asp:HyperLink runat="server" NavigateUrl='~/DiseaseInfo/Syndrome.aspx?
SyndromeID=<%# Eval("SYNDROME_ID")%>&SpeciesID=<%# Eval("SPECIES_ID")%>'
Text='<%# Eval("SYNDROME_NAME").ToString()%>'>
</asp:HyperLink>
This normally doesn't matter at a JavaScript / HTML level but the correct quote for C# / VB is a double quote which should be used within the Eval() method.
A slightly better approach would be to invoke a method to return this somewhat complex url:
<asp:HyperLink runat="server" NavigateUrl='<%# GetUrl() %>' />
protected string GetUrl()
{
return string.format("Syndrome.aspx?SyndromeID={0}...", Eval("SYNDROME_ID");
}
Here is how I ended up handling this:
Public Sub Repeater2_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim SpeciesID As String = CType(e.Item.DataItem, System.Data.DataRowView)("SPECIES_ID").ToString
Dim DiseaseID As String = CType(e.Item.DataItem, System.Data.DataRowView)("DISEASE_ID").ToString
Dim DiseaseName As String = CType(e.Item.DataItem, System.Data.DataRowView)("DISEASE_NAME").ToString
Dim Hyperlink = CType(e.Item.FindControl("Hyperlink1"), HyperLink)
Hyperlink.NavigateUrl = String.Format("~/DiseaseInfo/Disease.aspx?DiseaseID={0}&SpeciesID={1}", DiseaseID, SpeciesID)
Hyperlink.Text = DiseaseName
End If
End Sub
How is everyone today?
The Problem
Basically, I'm delving into the world of the AjaxControlToolkit today, with the main aim of fulfilling my AutoComplete requirements. I've set everything up as tutorialised and am a little confused as to why things aren't working (well I have an inkling as to what may be holding me back).
I've added the AjaxControlToolkit dll to my project and in my Markup I have the following :
at the top
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxControlToolkit" %>
then within my content
<ajaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxControlToolkit:ToolkitScriptManager>
<asp:TextBox ID="txtSearch" runat="server" CssClass="search"></asp:TextBox>
<ajaxControlToolkit:AutoCompleteExtender ID="autoCompleteSearchExtender" runat="server" TargetControlID="txtSearch" ServiceMethod="GetCompletionList"></ajaxControlToolkit:AutoCompleteExtender>
Then in the code behind, I have my nice little function (which the breakpoint within is never reached)
<System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()> _
Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
' Get current list
Dim myList As List(Of MyClass) = GetSearchResultList()
Return (From s In myList Select s.Name).ToArray()
End Function
The function is never being called, for a reason I am unsure of.
Potential Issues
There are a couple of potential issues where things may be going wrong:
I've tried adding the AjaxControlToolkit dll to the Toolbar in VS (2010), but all the controls are greyed out...
The GetCompletionList function (WebMethod) I have written is in the code behind the page. Could this not be called because it has to be in a Web Service perhaps?
I've also just realised that my function in the code behind isn't Shared, is this required? Because the list associated with the auto complete is dynamic.
Any help would be appreciated.
Thanks in advance.
Try putting your GetCompletionList function in a web-service (asmx is easiest). Make sure the the web-service class has a [ScriptService] attribute and that your function has a [ScriptMethod] attribute.
You'll also need to supply the path to the web-service in your AutoCompleteExtender's "ServicePath" property (i.e. ServicePath="~/MyService.asmx")
Also, you don't need the "contextKey" parameter in your function unless you are passing a context key from your AutoCompleteExtender control.
hth
Update: Add these attributes and try it. I have implemented and it works with page behind web methods.
ServiceMethod="yourGetfunction"
MinimumPrefixLength="2"
CompletionInterval="100"
EnableCaching="FALSE"
CompletionSetCount="20"
You can check this solution: http://suggester.codeplex.com/
Demo to test: http://show-demos.net/suggester/
Its not from ALAX Toolkit but it uses ASP.NET AJAX and jQuery and has more rich functionality
I kind of made this working:
<WebMethod()> _
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
Dim listData As New List(Of String)
listData.Add("A")
listData.Add("B")
listData.Add("C")
Return listData
End Function
My html:
<form id="maincontent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true">
</asp:ScriptManager>
<div>
<table style="margin-top:40px;color:White">
<tr>
<td>
Type in your search:
</td>
<td>
<asp:TextBox ID="searchBox" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ServiceMethod="GetCompletionList" MinimumPrefixLength="1"
CompletionInterval="10" EnableCaching="false" CompletionSetCount="1" TargetControlID="searchBox"
ID="AutoCompleteExtenderPersonSearch" runat="server" FirstRowSelected="false">
</asp:AutoCompleteExtender>
</td>
</tr>
</table>
</div>
</form>
Im having the following problem with vb.net asp.net webparts. Im trying to create a static connection between webparts but im running into a problem, namely:
Could not find the connection provider Web Part with ID 'Ucl_Diary_Summary1'
I have the following defined as my iterface:
Public Interface IDiaryPartsProvider
function Test as String
End Interface
I have the following as my Consumer (UserControl):
Partial Class UsrCtrls_Diary_ucl_DiaryAwaitingReview
Inherits System.Web.UI.UserControl
<ConnectionConsumer("Test", "myID")> _
Public Sub GetTextTransferInterface(ByVal provider As IDiaryPartsProvider)
Dim a As String = provider.Test()
UserMsgBox(a.ToString, Me.Page)
End Sub
End Class
I have the following defined as my Provider (UserControl):
Partial Class UsrCtrls_Diary_Diary_Summary
Inherits System.Web.UI.UserControl
Implements IWebPart, IDiaryPartsProvider
<ConnectionProvider("myID")> _
Public Function Test() As String Implements IDiaryPartsProvider.Test
Return "this is a test"
End Function
End Class
I have my default.aspx as follows:
<%# Register Src="UsrCtrls/Diary/ucl_Diary_Summary.ascx" TagName="ucl_Diary_Summary"
TagPrefix="uc4" %>
<%# Register Src="UsrCtrls/Diary/ucl_DiaryAwaitingReview.ascx" TagName="ucl_DiaryAwaitingReview"
TagPrefix="uc5" %>
<asp:WebPartManager ID="WebPartManager1" runat="server">
<StaticConnections>
<asp:WebPartConnection ID="cnn"
ConsumerID="Ucl_DiaryAwaitingReview1"
ProviderID="Ucl_Diary_Summary1"
/>
</StaticConnections>
</asp:WebPartManager>
<asp:WebPartZone ID="zoneDiaryTopLeft" runat="server" EmptyZoneText="Add WebPart Here" DragHighlightColor="#454777" HeaderText=" ">
<ZoneTemplate>
<asp:Panel ID="pnl1" runat="server" title="Claims Awaiting Review">
<asp:UpdatePanel ID="udp_TopLeft" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<uc5:ucl_DiaryAwaitingReview ID="Ucl_DiaryAwaitingReview1" runat="server" title="Claims Awaiting Review" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</ZoneTemplate>
</asp:WebPartZone>
<asp:WebPartZone ID="zoneDiaryTopRight" runat="server" EmptyZoneText="Add WebPart Here" DragHighlightColor="#454777" HeaderText=" ">
<ZoneTemplate>
<asp:Panel ID="PNL2" runat="server" title="Diary Summary">
<asp:UpdatePanel ID="udp_TopRight" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<uc4:ucl_Diary_Summary ID="Ucl_Diary_Summary1" runat="server" Title="Diary Summary" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</ZoneTemplate>
</asp:WebPartZone>
I can only assume its because I have my webparts - usercontrol wrapped in a panel (used for scrolling) and also an updatepanel which I use to refresh, so how do I get it to see the usercontrol?
Thanks in advance.
James.
I didn't have a chance to look at your message in detail but the issue appears to be with your provider. It should be returning an object that implements the interface used for communication to the consumer (usually a reference to itself).
Check out the following resource for more info:
Introducing ASP.NET Web Part Connections
I found out my problem/solution in the end.
Rob you are correct I needed to pass back an instance of the object implementing the interface but also, you cant reference a User Control for a static connection which is a child of two other controls, namely the panel and update panel. I was doing this all wrong. I changed it so that the update panel is inside the user control rather than on the default page. That way all the specific (web part) components are self contained.
Also, referring back to the original item of returning the instance, I replaced the following:
Public Function Test() As String Implements IDiaryPartsProvider.Test
Return "this is a test"
End Function
with:
<ConnectionProvider("myID")> _
Public Function Test() As IDiaryPartsProvider
Return me
End Function
Public ReadOnly Property Test() As String Implements IDiaryPartsProvider.Test
Get
Return "This is a test"
End Get
End Property
Hope this can help someone!
James.
I have an ASHX handler that returns an XML response (FileStructureXML.ashx).
Now I need to get the XML response from the ASHX handler and use it as a data source for my ASPX page.
If I point the XMLDataSource to a static XML file on the server, the treeview populates as expected. However, if I point the XMLDataSource to the ASHX handler instead of a static XML file on the server, it doesn't work.
Any help would be appreciated.
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView_Folders" runat="server" DataSourceID="FileXML">
<DataBindings>
<asp:TreeNodeBinding DataMember="Directory" TextField="Name" />
<asp:TreeNodeBinding DataMember="File" TextField="Name" />
</DataBindings>
</asp:TreeView>
</div>
<div>
<asp:XmlDataSource ID="FileXML" runat="server" DataFile="FileStructureXML.ashx">
</asp:XmlDataSource>
</div>
</form>
</body>
I think that the XmlDataSource only works with an actual file, not a URL. You might be able to work around this by not specifying a DataFile property and loading the Data property dynamically in your code behind. I think the FirstChild.OuterXml selection is correct, but you may need to experiment. I'm not in a place where I can test it.
XmlDocument treeDoc = new XmlDocument();
treeDoc.Load( "~/FileStructureXML.ashx" ); // this takes a URL
FileXml.Data = treeDoc.FirstChild.OuterXml; // everything after the xml definition
Dim oDataSet As New DataSet
Public Sub PopulateTree(ByVal ParentId As String, ByVal TVNode As TreeNode)
Dim oDataView As New DataView(oDataSet.Tables(0), "ParentID='" & ParentId & "'",
"DATA", DataViewRowState.OriginalRows)
Dim oDataRow As DataRowView
For Each oDataRow In oDataView
Dim oTreeNode As New TreeNode(oDataRow("DATA"))
Dim oComboBox As New ComboBox
If TVNode Is Nothing Then
Else
TVNode.Nodes.Add(oTreeNode)
PopulateTree(oDataRow("ID"), oTreeNode)
End If
Next
End Sub
This is how U call the above function
PopulateTree(0, tvPost.TopNode)
tvPost - its the name of TreeView T
To Read More Click this link
http://muruganad.com/ASP.NET/ASP_.NET_How_to_Populate_a_TreeView_Control_With_TreeNode_s_Using_recursive_algorithm_or_recursion_.html