'RatingControlChanged' is not a member of 'ASP.default_aspx'. - asp.net

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.

Related

Handles clause requires a WithEvents Callback

Error in CallbackUpdateSchema.Callback
BC30506 Visual Basic AND ASP.net Handles clause requires a WithEvents variable defined in the containing type or one of its base types. Callback
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.Xpo.DB
Public Class UpdateSchema
Inherits System.Web.UI.Page
Dim uow As UnitOfWork
Private Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
uow = XpoHelper.GetNewUnitOfWork
End Sub
Protected Sub CallbackUpdateSchema_Callback(source As Object, e As DevExpress.Web.CallbackEventArgs) Handles CallbackUpdateSchema.Callback
uow.UpdateSchema()
uow.CreateObjectTypeRecords()
End Sub
End Class
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="UpdateSchema.aspx.vb" %>
<%# Register assembly="DevExpress.Xpo.v18.2, Version=18.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Xpo" tagprefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxButton ID="ASPxButtonUpdateSchema" runat="server" AutoPostBack="False" Text="Update Schema">
<ClientSideEvents Click="function(s, e) {CallbackUpdateSchema.PerformCallback();}" />
</dx:ASPxButton>
<dx:ASPxCallback ID="CallbackUpdateSchema" runat="server" ClientInstanceName="CallbackUpdateSchema">
</dx:ASPxCallback>
</div>
</form>
</body>
</html>
Use the overridable method OnInit
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.oninit?view=netframework-4.8#System_Web_UI_Page_OnInit_System_EventArgs_
Events are meant for users. For sub-classing, you should use overridable methods instead.
Protected Overrides Sub OnInit(e As EventArgs)
MyBase.OnInit()
uow = XpoHelper.GetNewUnitOfWork
End Sub

vbCode is autocomplete is not working

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.

Visual Basic subprocedure issue

I'm working on some .NET code in visual studio web developer and I'm having an issue. When I double click on a button in design view, instead of loading a subprocedure, all it does is highlight this: <asp:Button ID="btnEnter" runat="server" Text="Enter" onclick="btnEnter_Click" />
When I try to run that just to see what happens, I get this error:
Line 8: <asp:Button ID="btnEnter" runat="server"
Compiler Error Message: BC30456: 'btnEnter_Click' is not a member of 'ASP.default_aspx'.
If I erase the onclick="btnEnter_Click" and run it, it works. Either way though, when I double click the button / element, shouldn't it create a subprocedure for me that looks something like?
Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
I've tried entering that manaully but the keywords don't turn blue or any sort of color, and when I run it, it just shows up as text on the webform with my other elements. Here is all I have so far:
<%# Page Title="Home Page" Language="VB"%>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Enter a person's name below"></asp:Label>
<p>
<asp:TextBox ID="txtStudentName" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="btnEnter" runat="server"
Text="Enter" onclick="btnEnter_Click" />
</p>
<p>
<asp:Button ID="btnDisplay" runat="server" Text="Display all and exit" />
</p>
<p>
<asp:Label ID="lbl2" runat="server" Text=" "></asp:Label>
</p>
<p>
<asp:Label ID="lbl3" runat="server" Text=" "></asp:Label>
</p>
<p>
<asp:Label ID="lbl4" runat="server" Text=" "></asp:Label>
</p>
<p>
<asp:Label ID="lbl5" runat="server" Text=" "></asp:Label>
</p>
</form>
Edit:
When I enter my code inside the default.aspx.vb file, it highlights keywords and such, but it can't reference the elements I created in the design view.
Partial Class _Default
Inherits System.Web.UI.Page
End Class
Class Lab1
Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs)
End Sub
Public Const length As Integer = 3
Shared counter2 As Integer = 0
Public Shared studentList As String() = New String(2) {}
Protected Sub btnEnter_Click(sender As Object, e As EventArgs)
Label1.Text = "Enter a person's name"
Dim studentName As [String] = txtStudentName.Text
If studentList.Length <= length Then
If txtStudentName.Text <> "" Then
Dim match As [Boolean] = True
Dim i As Integer = 0
While counter2 >= i
If studentList(i) IsNot Nothing Then
If studentList(i).ToUpper() = txtStudentName.Text.ToUpper() Then
match = False
Label1.Text = "This name has already been used"
End If
End If
i += 1
End While
If match = True Then
studentList(counter2) = txtStudentName.Text
counter2 += 1
End If
End If
End If
End Sub
End Class
Your Page declaration seems to say you are using inline style:
<%# Page Title="Home Page" Language="VB"%>
Which means your code is/should be within aspx file itself in a script runat="server" tag:
<%# Page Language="VB" %>
<!DOCTYPE html>
<script runat="server">
Protected Sub Button1_Click(sender As Object, e As EventArgs)
'Do something
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
However, your other code indicates you seem to want to use code-behind model, where you have .vb files (e.g. foo.aspx.vb)
The Page is declared like this for web sites (for web applications it will say CodeBehind="foo.aspx.vb"):
<%# Page Language="VB" AutoEventWireup="false" CodeFile="foo.aspx.vb" Inherits="foo" %>
You will find a foo.asp.vb file in your project
it's class name will be the name of your file (foo)
your code should be scoped to this class (I'm not sure what Class Lab1 in your post above is for....
foo.aspx.vb:
Partial Class foo
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Do something
End Sub
End Class
The "fix" is for you to:
choose which model you want to write code: inline or code-behind
declare the Page appropriately
for inline, your code will be in the aspx file itself
for code-behind, your code will live, and should be encapsulated within the Class file of the page.
The Page declaration actually says so:
CodeFile="foo.aspx.vb" is the file where the code is
Inherits="foo" is the Partial Class in the file (Partial Class foo)
Try this
Private Sub btnEnter_Click(sender As Object, e As System.EventArgs) Handles btnEnter.Click
End Sub
Here, btnEnter_Click is your event name and use the Handles keyword at the end of a procedure declaration to cause it to handle events raised by an object variable

Nesting ASP.NET user controls programmatically

I have a user control that programmatically includes a second user control several times, but the end result is that no HTML is generated for the controls at all.
Default.aspx
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="TestApplication._Default" %>
<%# Register TagName="Ten" TagPrefix="me" Src="~/Ten.ascx" %>
<html>
<head runat="server"></head>
<body>
<form id="form1" runat="server">
<me:Ten ID="thisTen" runat="server" />
</form>
</body>
</html>
Ten.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="Ten.ascx.vb" Inherits="TestApplication.Ten" %>
<asp:Panel ID="List" runat="server"></asp:Panel>
Ten.ascx.vb
Public Class Ten
Inherits System.Web.UI.UserControl
Protected Sub Page_Init() Handles Me.Init
For I As Integer = 0 To 11
List.Controls.Add(New One(I.ToString))
Next
End Sub
End Class
One.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="One.ascx.vb" Inherits="TestApplication.One" %>
<asp:Button ID="OneButton" Text="Press ME!" runat="server" />
One.ascx.vb
Public Class One
Inherits System.Web.UI.UserControl
Private _number As String
Sub New(ByVal number As String)
_number = number
End Sub
Protected Sub OneButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OneButton.Click
Dim script As String = "<script type=""text/javascript"">" +
"alert('Button " + _number + "');" +
"</script>"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ServerControlScript", script, True)
End Sub
End Class
Edit:
Using load control (Ten.aspx)
Dim p() As String = {I.ToString}
Dim o As One = Me.LoadControl(New One("").GetType, p)
List.Controls.Add(o)
Edit 2:
Dim o As One = Me.LoadControl("~/One.ascx")
o._number = I.ToString
List.Controls.Add(o)
I wouldn't perform this operation in the OnInit event, but this may or may not be related to your issue. Instead, I would load the controls in the OnLoad event.
However, using the new keyword is not typically how user controls are loaded. Sorry, but I only know C# and don't know the exact translation:
In C#:
One one = (One)this.LoadControl("~/Controls/One.ascx");
Does this look right in VB.NET?
Dim one As One = Me.LoadControl("~/Controls/One.ascx")
You'll likely have to delete the constructor and just set the property after you load the control.

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