I want to set asp label to catch Cookie content,
I set
<p><asp:Label ID="lblUserID" runat="server" Text=""></asp:Label></p>
in USERINFO.aspx
then set
Public Class USERINFO
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If (Request.Cookies("userInfo")("vID") IsNot Nothing) Then
lblUserID.Text = Request.Cookies("userInfo")("vID").ToString
End If
End If
End Sub
End Class
in USERINFO.aspx.vb
But got visual studio alert :lblUserID not defined
What should I do to connect the label correctly ?
I am not sure exactly, but you may still double-check if there's no typo in design and code-behind files.
Also, I noticed you're using ToString without parentheses, which is not correct. Please change it to -
lblUserID.Text = Request.Cookies("userInfo")("vID").ToString()
Thanks to #Andrew Morton, I solve the problem.
My issue is caused by that I didn't declare lblUserID in in USERINFO.aspx.designer.vb,
I also didn't wrote the Inherits tag in USERINFO.aspx like
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="USERINFO.aspx.vb" **Inherits="MyProject.USERINFO"** %>
Correctly.
Related
On a legacy ASP.NET project I'm trying to maintain, there is what seems to be a spurious design-time error, namely, that a property is inaccessible. It is declared Public. It works at runtime.
To troubleshoot, I added a new WebForm to the project to simplify things.
Public Class Logon2017
Inherits System.Web.UI.Page
Dim _Foo As Boolean
Public Property Foo As Boolean
Get
Return True
End Get
Set(value As Boolean)
_Foo = value
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
And on the ASPX page:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="Logon2017.aspx.vb" Inherits="BlahBlah.Logon2017" %>
<snip>
.
.
.
<script type="text/javascript">
var s = <%=Foo%>
</script>
In the editor in Visual Studio 2015, HTML view, "Foo" is underlined in red with the error that it is not declared.
What causes the ASPX page to be unable to find the Property declaration in the code-behind?
Is there some pointer in one of the project files that has gotten corrupted?
So In my somepage.aspx.vb I have this
Public Class somepage
Inherits System.Web.UI.Page
Protected Property StringToPass As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
StringToPass = "hello"
End Sub
End Class
and then in the .aspx I try to do this
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="somepage.aspx.vb" Inherits="mywebpage.somepage" %>
...
<%=StringToPass%>
...
but this doesn't work as expected, the .aspx file has no idea of its existence. How do I get that string from A to B?
EDIT: actually it does work, when I load the page, the string is passed. Its just that the debugger thinks StringToPass is an undeclared variable, whats up with that?
The following method is return an error: 'Event init cannot be found' and get error on System.Web.UI.Page
Visual Studio 2010, framework 3.5
Public Class_default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
End Sub
I am not VB.NET expert (I am writing on C#) but i can say that the cause of the problem is that you need to override OnInit method instead of Page_Init.
So, you need to use the following code:
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Friend Overrides Sub OnInit(ByVal e As EventArgs)
MyBase.OnInit(e)
End Sub
End Class
I think Maxim is correct, however you can also add your event handler by doing:
AddHandler Me.Init, AddressOf Page_Init
I think that's right, sorry my VB is pretty rusty.
Well,
I assume you are using AutoEventWireup="true" in your markup but you have also marked your handler with the Handles keyword.
AutoEventWireup won't work, its not able to access private members of your class directly.
Set AutoEventWireup="false" and save its needless performance penalty, the handler should still fire because it explicitly Handles the Page.Init event.
Since you're handling the event explicitly you are also free to change the name of the event handler and remove the ugly _.
The majority of your Crystal Reports code is likely in the Page_Load event. If you move it to the Page_Init you'll find it works correctly.
i am using the WebBrowser control in asp.net page. here is the simple code:
Public Class _Default
Inherits System.Web.UI.Page
Private WithEvents browser As WebBrowser
Dim th As New Threading.Thread(AddressOf ThreadStart)
Sub ThreadStart()
browser = New WebBrowser
AddHandler browser.DocumentCompleted, AddressOf browser_DocumentCompleted
browser.Navigate("http://www.someurl.com/")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
th.SetApartmentState(Threading.ApartmentState.STA)
th.Start()
th.Join()
End Sub
Private Sub browser_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
If browser.Document IsNot Nothing Then
Dim textbox As HtmlElement = browser.Document.GetElementById("txt1")
textbox.InnerText = "some text"
Dim button As HtmlElement = browser.Document.GetElementById("btn1")
button.InvokeMember("click")
End If
End Sub
End Class
the problem is that the webbrowser's DocumentCompleted event is not being handled. It looks like the page request finishes before anything else could happen.
what's the solution to this problem?
I really recommend reading this article(He won a price for it..)
Using the WebBrowser Control in ASP.NET
http://www.codeproject.com/KB/aspnet/WebBrowser.aspx
His solution is to create 3 threads for it to work..
I'm not sure but I have some concerns about the way you wrote your code.
You are creating and initializing your thread as soon as your class instance is created. This is before the form has been loaded.
I can't say for sure this couldn't work but I would definitely recommend creating the thread in your Load event handler, just before you use it.
I wrote some similar code in C# to generate a website thumbnail. Although that code does not use the DocumentCompleted event, I played with that event when I wrote it and it seemed to work okay. You can compare my code to yours.
Also, I should mention I have one hosting account where the code doesn't work. It seems to simply die when I call Thread.Join. However, it doesn't appear that's the issue you're running into.
this code never fills the grid view I know that somthing is wrong here the code
Imports System.Data
Imports ZidduDataSetTableAdapters
Partial Class _Default
Inherits System.Web.UI.Page
Dim filesAdp As New FilesTableAdapter
Dim filestable As New ZidduDataSet.FilesDataTable
Protected Sub btnfill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnfill.Click
Me.GridView1.DataSource = filesAdp.GetData
Me.GridView1.DataBind()
End Sub
End Class
and I already created the dataset with wizard called ZidduDataSet.xsd
and the adapter name is FilesTableAdapter
can any one help?
i am not a VB coder, but i think you should call Databind() function on Page Load event too.
hope this helps.
the only thing wrong with the code is that filestable is never used. If your gridview isn't showing up then you have a problem else where i think.
btnfill_Click isn't getting called. Check the .aspx markup to make sure the event handler is referenced.
filesAdp.GetData doesn't return any data.
GridView1 isn't visible on the page.