vbCode is autocomplete is not working - asp.net

I am new to VB.net I want get list of names from my DB with auto complete. I am trying to follow the following example.
But My problem is it not working and I was not getting any error can any one tell me where I am doing wrong.
My home.aspx
<%# Page Title="Home Page" Language="VB" CodeFile="~/home.aspx.vb" AutoEventWireup="true" Inherits="_home"%>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="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">
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScripManager1" runat="server"/>
<asp:UpdatePanel ID="autoupdate" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
TargetControlID="txtSearch" ServiceMethod="GetList" MinimumPrefixLength="3"
UseContextKey="True" >
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
This is my home.aspx.vb
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Web.Services
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
Try
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Test").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("select LoginName from users where LoginName like '#Name' +'%' ", con)
cmd.Parameters.AddWithValue("#Name", prefixText)
'Dim da As New SqlDataAdapter(cmd)
'Dim dt As New DataTable()
'da.Fill(dt)
'Dim InviteSearchListresult As New List(Of String)()
'For i As Integer = 1 To dt.Rows.Count
' InviteSearchListresult.Add(dt.Rows(i)(1).ToString())
' Next
Dim result As New List(Of String)()
Dim dr As SqlDataReader = cmd.ExecuteReader()
While dr.Read()
result.Add(dr("LoginName").ToString())
End While
Return (
From m In result
Where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase)
Select m).Take(count).ToArray()
Catch ex As Exception
End Try
End Function
End Class
Please help how to solve this issuse.

Your service method is GetList but your actual method name is GetCompletionList.
Try getting the method names to match up and see if that's the problem. You're trying to call a method that doesn't exist.

Related

Add event onserverclick when a load usercontrol

So I searched but could not solve my problem.
please help.The user control is loaded. But onserverclick event does not work.
WebFormTest.aspx
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="WebFormTest.aspx.vb" Inherits="MS2.WebFormTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%=MS2.CLoadUC.RenderUserControl("/Site/testUC.ascx")%>
</div>
</form>
</body>
</html>
testUC.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="~/testUC.ascx.vb" Inherits="MS2.testUC" %>
<script runat="server">
Protected Sub Button1_Click(sender As Object, e As EventArgs) 'Handles Button1.ServerClick
Dim a = "test"
End Sub
</script>
<button ID="Button1" runat="server" onserverclick="Button1_Click">Button</button>
CLoadUC.RenderUserControl("/Site/testUC.ascx")
Imports System.IO
Imports System.Reflection
Public Class CLoadUC
Public Shared Function RenderUserControl(path As String) As String
Dim pageHolder As New Page
Dim viewControl As UserControl = DirectCast(pageHolder.LoadControl(path), UserControl)
Dim viewControlType As System.Type = viewControl.GetType()
'Return viewControl
pageHolder.Controls.Add(viewControl)
Dim output As New StringWriter()
HttpContext.Current.Server.Execute(pageHolder, output, False)
Return output.ToString()
End Function
End Class

Webmethod from WebService doesn't fire for AJAX AutoCompleteExtender and UpdatePanel

Here is code:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true"
AsyncPostBackTimeout="1000" ScriptMode="Release"
EnablePartialRendering="true" >
<Services>
<asp:ServiceReference Path ="~/FolderForService/Service.asmx" />
</Services>
<Scripts>
<asp:ScriptReference Path="~/jscript/common.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="upFSK" runat ="server" UpdateMode ="Conditional" >
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" >
<asp:TextBox ID="TextBox1" runat="server" Visible="True" Width="128px"></asp:TextBox>
<cc1:AutoCompleteExtender ID="ACE"
runat="server"
ServicePath="~/FolderForService/Service.asmx"
ServiceMethod="WebMethod"
MinimumPrefixLength="4"
CompletionSetCount = "10"
TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
</Panel>
</ContentTemplate>
</UpdatePanel>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Linq
Imports System.Web.Caching
Imports System.Data
Imports System.Collections.Generic
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
'Web method which doesn't fire
<WebMethod()> _
Public Shared Function WebMethod(ByVal prefixTekst As String, ByVal count As Integer) As List(Of String)
' Code
End Function
End Class
What I did:
I moved textbox outside Update Panel - 0 points
Changed WebMethod from shared to instance - 0 points
Moved WebService to root - 0 points
Added PostBack=true and Triggers to UpdatePanel with textbox as a trigger - 0 points
Created new WebSite with AutoComplete TextBox and without UpdatePanel - 10 points
What did I miss?
I've only done this in c#, I can give you a c# example if you request it otherwise check out this resource, it should help you get this operational. http://www.aspsnippets.com/Articles/ASP.Net-AJAX-Control-Toolkit-AutoCompleteExtender-without-using-Web-Services.aspx
From the link:
ASP:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>
VB:
<System.Web.Script.Services.ScriptMethod(), _
System.Web.Services.WebMethod()> _
Public Shared Function SearchCustomers(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("constr").ConnectionString
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select ContactName from Customers where" & _
" ContactName like #SearchText + '%'"
cmd.Parameters.AddWithValue("#SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim customers As List(Of String) = New List(Of String)
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
customers.Add(sdr("ContactName").ToString)
End While
conn.Close()
Return customers
End Function
Set your page property EnableEventValidation="false".It will work.

'RatingControlChanged' is not a member of 'ASP.default_aspx'.

net using VB. I followed this tutorial for doing my ratings controller
But I am getting the following error
Error 1 'RatingControlChanged' is not a member of 'ASP.default_aspx'. C:\Users\raj\Documents\Visual Studio 2013\WebSites\WebSite13\Default.aspx 46
Error 2 'ratingControl' is not declared. It may be inaccessible due to its protection level. C:\Users\raj\Documents\Visual Studio 2013\WebSites\WebSite13\Default.aspx.vb 16 48 WebSite13
Error 3 'ratingControl' is not declared. It may be inaccessible due to its protection level. C:\Users\raj\Documents\Visual Studio 2013\WebSites\WebSite13\Default.aspx.vb 33 13 WebSite13
Error 4 'lbltxt' is not declared. It may be inaccessible due to its protection level. C:\Users\raj\Documents\Visual Studio 2013\WebSites\WebSite13\Default.aspx.vb 34 13 WebSite13
I have no idea which one is causing the error My DB name is Test and Table name is ratings
This is my default.aspx
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ajax Rating Sample</title>
<style type="text/css">
.ratingEmpty
{
background-image: url(ratingStarEmpty.gif);
width:18px;
height:18px;
}
.ratingFilled
{
background-image: url(ratingStarFilled.gif);
width:18px;
height:18px;
}
.ratingSaved
{
background-image: url(ratingStarSaved.gif);
width:18px;
height:18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScripManager1" runat="server"/>
<div>
<asp:UpdatePanel ID="pnlRating" runat="server">
<ContentTemplate>
<table style="width:35%">
<tr>
<td style="width:20%">
<b>Average Rating:</b>
</td>
<td>
<ajax:Rating ID="ratingControl" AutoPostBack="true" OnChanged="RatingControlChanged" runat="server" StarCssClass="ratingEmpty" WaitingStarCssClass="ratingSaved" EmptyStarCssClass="ratingEmpty" FilledStarCssClass="ratingFilled">
</ajax:Rating>
<b> <asp:label ID="lbltxt" runat="server"/> </b>
</td>
</tr>
<tr>
<td colspan="2">
Testing
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
This is default.aspx.vb code
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Private con As New SqlConnection(ConfigurationManager.ConnectionStrings("test").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindRatingControl()
End If
End Sub
Protected Sub RatingControlChanged(ByVal sender As Object, ByVal e As AjaxControlToolkit.RatingEventArgs)
con.Open()
Dim cmd As New SqlCommand("insert into rating(rate)values(#Rating)", con)
cmd.Parameters.AddWithValue("#Rating", ratingControl.CurrentRating)
cmd.ExecuteNonQuery()
con.Close()
BindRatingControl()
End Sub
Protected Sub BindRatingControl()
Dim total As Integer = 0
Dim dt As New DataTable()
con.Open()
Dim cmd As New SqlCommand("Select Rate from rating", con)
Dim da As New SqlDataAdapter(cmd)
da.Fill(dt)
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
total += Convert.ToInt32(dt.Rows(i)(0).ToString())
Next
Dim average As Integer = total \ (dt.Rows.Count)
ratingControl.CurrentRating = average
lbltxt.Text = dt.Rows.Count & "user(s) have rated this article"
End If
End Sub
End Class
So can any Help me how to solve this issuse.
Your default.aspx page (front end) appears to be missing the needed page declaration - this is what tells it which codebehind to use.
It should be at the very top line of the default.aspx file.
An example default page declaration:
<%# Page Title="Home Page" Language="VB.net" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebTest._Default" %>
The important pieces are:
CodeBehind="Default.aspx.cs"
Inherits="WebTest._Default"
This tells the ASP.net engine which file and class name to associate with the page.
Are you sure you didn't accidentally erase that line and save the file?
This should be easy to restore, just copy from another file and fix the CodeBehind and Inherits (and Title) attributes to have the proper values.

Using SqlBulkCopy SqlRowsCopied to update a label

I have a simple web application that is reading records from a CSV file and storing them in a database table. Then I am using SqlBulkCopy to copy the records into an SQL database using batches. All is fine with the insert. I am trying to give the user some feedback using OnSqlRowsCopied and NotifyAfter. The goal is to update a label that is contained in an UpdatePanel to display the number of records copied at the current NotifyAfter interval. However, the label will not update until SqlBulkCopy has complete. I can see that the s_OnSqlRowsCopied event is firing using Debug.WriteLine. What is the reason why the label won't update and how can I overcome this?
Code Behind
Imports System.Data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Dim filePath As String
Dim rowsCopied As String
Public Sub btnGetCSV_Click(sender As Object, e As EventArgs) Handles btnGetCSV.Click
filePath = System.IO.Path.GetFullPath(fileUpload1.PostedFile.FileName)
lblInfo.Text = filePath
End Sub
Protected Sub btnToSQL_Click(sender As Object, e As EventArgs) Handles btnToSQL.Click
Dim cs As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("csMediaPortal").ConnectionString
CopyData(CSVtoDataTable(lblInfo.Text.ToString()), cs)
End Sub
Private Function CSVtoDataTable(filePath As String) As DataTable
Dim dt As DataTable = Nothing
Dim sourcePath As String = String.Empty
Dim csvFile As String = String.Empty
Dim conString As String = String.Empty
Dim conn As OleDb.OleDbConnection = Nothing
Dim adapter As OleDb.OleDbDataAdapter = Nothing
Dim selString As String = String.Empty
Try
sourcePath = System.IO.Path.GetDirectoryName(filePath)
csvFile = System.IO.Path.GetFileName(filePath)
conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sourcePath & ";Extended Properties=""text;HDR=No;FMT=FixedLength"""
conn = New OleDb.OleDbConnection(conString)
selString = "Select * From " & csvFile
adapter = New OleDb.OleDbDataAdapter(selString, conn)
dt = New DataTable(System.IO.Path.GetFileNameWithoutExtension(filePath))
conn.Open()
adapter.Fill(dt)
conn.Close()
Catch ex As Exception
lblInfo.Text = ex.Message
Finally
adapter.Dispose()
conn.Dispose()
End Try
Return dt
End Function
Protected Sub CopyData(sourceTable As DataTable, cs As String)
Using s As SqlBulkCopy = New SqlBulkCopy(cs, SqlBulkCopyOptions.UseInternalTransaction)
s.DestinationTableName = "test"
s.BatchSize = 1000
Try
AddHandler s.SqlRowsCopied, AddressOf s_OnSqlRowsCopied
s.NotifyAfter = 900
s.WriteToServer(sourceTable)
Catch ex As Exception
DirectCast(DirectCast(HttpContext.Current.Handler, Page).FindControl("lblInfo"), Label).Text = "Commit Error: " & ex.Message
End Try
s.Close()
End Using
End Sub
Protected Sub s_OnSqlRowsCopied(sender As Object, e As SqlRowsCopiedEventArgs)
Me.lblProgress.Value = e.RowsCopied.ToString()
Me.UpdatePanel1.Update()
Debug.WriteLine(e.RowsCopied)
End Sub
End Class
Web Form
<%# Page Language="vb" CodeBehind="WebForm1.aspx.vb" Inherits="CSVUpload.WebForm1" %>
<!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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:FileUpload ID="fileUpload1" runat="server" />
<asp:Button ID="btnGetCSV" runat="server" Text="Post" OnClick="btnGetCSV_Click" />
<asp:Label ID="lblInfo" runat="server" Text="Label"></asp:Label>
</div>
<asp:Button ID="btnToSQL" runat="server" Text="Insert To SQL" OnClick="btnToSQL_Click" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<input runat="server" type="text" id="lblProgress" value="0" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

calling vb pagemethod from ajax

Hi
I have a simple aspx file with 2 text boxes and an ajax autocomplete extender attached to textbox2
<%# Page Language="VB" AutoEventWireup="false" CodeFile="test4.aspx.vb" Inherits="test4" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="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">
<body>
<form id="form1" runat="server">
<div id="content">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server">
</asp:TextBox>
</div>
<asp:AutoCompleteExtender ID="load_textBox2" TargetControlID="TextBox2" ServiceMethod="GetModelName"
UseContextKey="True" runat="server">
</asp:AutoCompleteExtender>
</form>
</body>
</html>
What i am trying to do is to call the pagemethod "GetModelName" form the aspx.vb to fillup the textbox2 with the relevent data
This is the aspx.vb code
Imports System.Web.Services
Partial Class test4
Inherits System.Web.UI.Page
Dim Model_Name_old As String()()
Dim mod_code As String()
Dim mod_name As String()
Dim cod_upper As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
//calling webservice that retunrs a jagged array
Dim ins As New localhost_insert_model.dbModel
Model_Name_old = ins.get_Model_Name("A")
mod_code = Model_Name_old(0)
mod_name = Model_Name_old(1)
cod_upper = Model_Name_old(0).GetUpperBound(0)
End Sub
<WebMethod()>
Public Function GetModelName() As String()
Return mod_name
End Function
End Class
This not working.. How can i make it work???.
Your function should be shared:
<WebMethod()>
Public Shared Function GetModelName() As String()
Return mod_name
End Function
Check that EnablePageMethods="true" in the script manager tag.

Resources