Created By
DMG Development
As Seen On

Main Page  |  Forums  |  Register  |  Active Topics  |  Members  |  Search

 
Username:
Password:
DMG Forums >> DMG Forums Discussion >> General Discussion >> Page Load Event
Page Load Event
Author Topic
enginuysal


Newbie

Join Date: 9/18/2007
Posts: 7

Posted: 10/14/2007 6:06:15 AM

I'm trying to import DMG Forums into my existing application which allows only registered users in it. I'm trying to modify global.vb page_load event so that whenever a user gets an e-mail notification about a new post to a forum subscribed and clicks the link into it page_load event validates him.

The code I wrote to page_load event in Global.vb / Login /
Code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

If Page.User.Identity.IsAuthenticated = False Then
Session("UserLogged") = "0"
Session("UserID") = ""
Session("UserName") = ""
Session("UserLevel") = "0"
Else

Using conn As New SqlConnection("Data Source=72.52.146.58;Initial Catalog=forum;User ID=umutuygar;Password=UUuu1234")
conn.Open()
Dim cmd As New SqlCommand("SELECT MEMBER_ID, MEMBER_USERNAME, MEMBER_PASSWORD, MEMBER_LEVEL FROM _MEMBERS", conn)
Dim yeni As New SqlDataSource("Data Source=72.52.146.58;Initial Catalog=forum;User ID=umutuygar;Password=UUuu1234", "SELECT MEMBER_ID, MEMBER_USERNAME, MEMBER_PASSWORD, MEMBER_LEVEL FROM _MEMBERS")
Dim dssa As New DataSourceSelectArguments()
Dim sda As New SqlDataAdapter(cmd.CommandText, conn)
Dim dt As DataTable = DirectCast(yeni.[Select](dssa), DataView).ToTable()
Dim ds As New DataSet()
sda.Fill(ds)

For Each row As DataRow In ds.Tables(0).Rows
If row("MEMBER_USERNAME").ToString() = Page.User.Identity.Name.ToString() Then
Session("UserLogged") = "1"
Session("UserID") = row("MEMBER_ID").ToString()
Session("UserName") = row("MEMBER_USERNAME").ToString()
Session("UserLevel") = row("MEMBER_LEVEL").ToString()
End If
Next
End Using
End If
End Sub


When I compile it, it gives the following error.

Code:

ERROR: Type SqlDataSource is not known
ERROR: Type DataSourceSelectArguments is not known


I included
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes

in declerations section.

What do you think the problem could be?

Kind Regards,
Engin Uysal

enginuysal


Newbie

Join Date: 9/18/2007
Posts: 7

Posted: 10/14/2007 9:37:56 AM

I was missing System.Web.UI and System.Web.UI.WebControls

Thanks anyway,


rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 1/28/2009 5:23:39 PM

I am trying something similar, except when the user selects the link in the email and they are not authenticated, it will redirect the user to the Login page:

If User.Identity.IsAuthenticated = "False" Then
Response.Redirect("~/Login.aspx")
End If

I place this code first off in the page_load event, however nothing happens. I have tried commenting out the if statement but there is still no effect. What am I missing?

Thanks,

Reed

rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/2/2009 9:01:21 AM

Still in need of suggestions.

Thanks,

Reed

grimmeissen


Administrator


Join Date: 8/30/2005
Posts: 656
Location: Cincinnati, Ohio

Posted: 2/2/2009 10:45:37 AM

So the response.redirect is not working at all? If you comment out the if it still doesn't jump?
rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/2/2009 5:12:10 PM

No - I do not understand why I am having some trouble editing the code. I was also trying to modify the code in Forums.vb so the email sent to subscribers contains the message of the reply. Here is the other code:

Public Shared Sub SendToSubscribers(ByVal TopicID as Integer)
if ((Settings.EmailAllowSub = 1) and (Settings.AllowSub = 1)) then
Dim TopicSubject As String = ""
Dim ReplyMessage As String = ""
Dim ReplyAuthor As String = ""
Dim ReplyDate As DateTime = ""
Dim Reader3 As OdbcDataReader = Database.Read("SELECT TOP 1 DMG_REPLIES.REPLY_DATE, DMG_REPLIES.REPLY_ID, DMG_REPLIES.REPLY_MESSAGE, DMG_MEMBERS.MEMBER_USERNAME FROM DMG_REPLIES INNER JOIN DMG_MEMBERS ON DMG_REPLIES.REPLY_AUTHOR = DMG_MEMBERS.MEMBER_ID WHERE DMG_REPLIES.TOPIC_ID = '" & TopicID & "' ORDER BY DMG_REPLIES.REPLY_ID DESC")
While Reader3.Read()
ReplyMessage = Reader3("REPLY_MESSAGE")
ReplyAuthor = Reader3("MEMBER_USERNAME")
ReplyDate = Reader3("REPLY_DATE")
End While
Reader3.Close()
Dim Reader As OdbcDataReader = Database.Read("SELECT M.MEMBER_EMAIL FROM " & Database.DBPrefix & "_SUBSCRIPTIONS S Left Outer Join " & Database.DBPrefix & "_MEMBERS M On S.SUB_MEMBER = M.MEMBER_ID WHERE S.SUB_TOPIC = " & TopicID & " AND S.SUB_EMAIL = 1")
if Reader.HasRows() then
Dim Reader2 as OdbcDataReader = Database.Read("SELECT TOPIC_SUBJECT FROM " & Database.DBPrefix & "_TOPICS WHERE TOPIC_ID = " & TopicID)
While Reader2.Read()
TopicSubject = Reader2("TOPIC_SUBJECT").ToString()
End While
Reader2.Close()

While Reader.Read()
Dim FullPath as String = GetFullURLPath()
Dim Mailer As Integer = SendEmail(Reader("MEMBER_EMAIL").ToString(), Settings.EmailAddress, Settings.PageTitle & " : Thread Updated", Functions.CustomMessage("EMAIL_SUBSCRIPTION") & "<br /><br />On " & ReplyDate & " " & ReplyAuthor & " said:<br/><br/>" & ReplyMessage & "<br /><br />THREAD: " & TopicSubject & "<br /><br /><a href=""" & FullPath & "/topics.aspx?ID=" & TopicID & """>" & FullPath & "/topics.aspx?ID=" & TopicID & "</a>")
End While
end if
Reader.Close()
end if
End Sub

This has no effect. I don't understand why it is not working for me - what am I doing wrong?

empkey2


Intermediate

Join Date: 2/20/2008
Posts: 74

Posted: 2/2/2009 5:39:15 PM

1) Check if your smtp information was setup properly, ie, emails can be sent from your forums.
2) then check if everything regarding emails sent was get correctly.




rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/2/2009 5:42:40 PM

Thanks empkey2 for the suggestions. The system successfully sends emails but when I made the changes so the above is the code, nothing changes about the emails I receive.

empkey2


Intermediate

Join Date: 2/20/2008
Posts: 74

Posted: 2/3/2009 12:03:08 AM

If so; you may have problems with reader3,2,1.

I guess that the reader3 object was not created successfully. If you use MySql database, the sql statement: "SELECT TOP 1..." cannot work. Please use "LIMIT m,n".
You'd better use the second parameter in Database.Read function to specify the number of records read.




grimmeissen


Administrator


Join Date: 8/30/2005
Posts: 656
Location: Cincinnati, Ohio

Posted: 2/3/2009 9:58:58 AM

I also suggest following empkey's suggestion on the Database.Read() function. It takes two paramenters, the first being a string representing the SQL query, and the second being an integer representing the number of records you want. This was put in place because MySQL and SQL Server have different functions for "TOP".

Another very simple thing I might ask is whether or not you re-compiled after making these changes? It seems silly, but maybe after making these code changes you didn't get the updated DLL's in your /bin folder.
rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/3/2009 3:32:19 PM

You are correct. The dll's needed to be recompiled. I guess I was too ignorant to understand the process. I was receiving some errors however (such as TopicsFontColor and TopicsFontSize does not exist in Settings). I add these items to Global.vb and recompiled but now I have another error and I am not sure how to fix it. See below:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'ShowTopicFileUpload' is not declared.

Source Error:



Line 114: <font size="<%=Settings.TopicsFontSize%>" color="<%=Settings.TopicsFontColor%>">
Line 115: <%# FormatString(DataBinder.Eval(Container.DataItem, "TOPIC_MESSAGE")) %>
Line 116: <%# IIF((DataBinder.Eval(Container.DataItem, "TOPIC_FILEUPLOAD") = ""), "", ShowTopicFileUpload(DataBinder.Eval(Container.DataItem, "TOPIC_FILEUPLOAD"))) %>
Line 117: <%# IIF((DataBinder.Eval(Container.DataItem, "MEMBER_LEVEL") = -1), "", Signature(DataBinder.Eval(Container.DataItem, "TOPIC_SIGNATURE"), DataBinder.Eval(Container.DataItem, "MEMBER_SIGNATURE"))) %>
Line 118: </font>


Is the Global.vb file I am using an older version? I downloaded the 3.2 updgrade and copied the files (I don't think there was an updated version of Global.vb though). As always, your help is greatly appreciated.

Thanks,

Reed

grimmeissen


Administrator


Join Date: 8/30/2005
Posts: 656
Location: Cincinnati, Ohio

Posted: 2/4/2009 12:26:01 PM

It does look like you are using an old version of Global.vb, but this file is definitely included in the upgrade package.

Take note that the location of source files has changed in version 3.2. There is now a SOURCE folder with all of the .vb files in it. You can get rid of the .vb files that used to be in the root folder and make sure you compile with the Compile.bat file.

The batch file will properly compile global.vb first and then it is used as a dependency for the rest.
rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/4/2009 3:32:58 PM

Thanks! I missed that. I will play with it.

rhasting


Beginner

Join Date: 1/9/2009
Posts: 13

Posted: 2/5/2009 12:55:58 PM

That was it! It is working great now! Thank you!


  Copyright DMG Development DMG Forums 3.2