Created guestbook

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/2/2010 1:56:38 PM
Gravatar
Total Posts 76

Created guestbook

Hello,

With some code copied from the web i have a questbook integrated in my website.

Everything is working well when using this as an custom module.

The only problem is when there are more then 10 messages a new page is created (Datagrid.PageSize=10). When i click for the next page the next page isn't being shown?!

What could this be?

<%@ Control Language="VB" ClassName="Gastenboek" Debug="True" %>

<%@ import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

Dim str1 As String = ConfigurationManager.AppSettings("MSSQLConnectionString")

Dim strMessageSurround, strMessageMiddle, strGuestBookName As String

Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'#### User Configuration ##########

strMessageSurround = "#c9c19f"
strMessageMiddle = "#f4f0e2"
strGuestBookName = "Zootje Ongeregeld Gastenboek"
Const MsgPerPage = "10"

'#### End User Configuration #######

If Not (IsPostBack) Then
bindGrid()
End If
viewGrid.PageSize = MsgPerPage
End Sub

Sub bindGrid()
Dim strSQL As String = "SELECT id, name, email, message, TheDate FROM messages ORDER BY TheDate DESC;"
Dim objConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(str1)
Dim objAdapter As New SqlDataAdapter(strSQL, objConnection)
Dim objDataSet As New DataSet()

objAdapter.Fill(objDataSet, "messages")

Dim objDataView As New DataView(objDataSet.Tables("Messages"))

viewGrid.DataSource = objDataView
viewGrid.DataBind()
End Sub

Sub viewGrid_Paged(sender as Object , e as DataGridPageChangedEventArgs)
viewGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Public Function smileFilter(ByVal smiles As String) As String
smiles = Replace(smiles, "[angel]", "<img src='smileys/angel_smile.gif'>")
smiles = Replace(smiles, "[angry]", "<img src='smileys/angry.gif'>")
smiles = Replace(smiles, "[teeth]", "<img src='smileys/baring_teeth.gif'>")
smiles = Replace(smiles, "[confused]", "<img src='smileys/confused.gif'>")
smiles = Replace(smiles, "[cry]", "<img src='smileys/cry.gif'>")
smiles = Replace(smiles, "[dunno]", "<img src='smileys/dont_know.gif'>")
smiles = Replace(smiles, "[ssh]", "<img src='smileys/dont_tell.gif'>")
smiles = Replace(smiles, "[haha]", "<img src='smileys/hahaha.gif'>")
smiles = Replace(smiles, "[nerd]", "<img src='smileys/nerd.gif'>")
smiles = Replace(smiles, "[omg]", "<img src='smileys/omg.gif'>")
smiles = Replace(smiles, "[party]", "<img src='smileys/party.gif'>")
smiles = Replace(smiles, "[red]", "<img src='smileys/red.gif'>")
smiles = Replace(smiles, "[smile]", "<img src='smileys/regular_smile.gif'>")
smiles = Replace(smiles, "[rolleyes]", "<img src='smileys/roll.gif'>")
smiles = Replace(smiles, "[sad]", "<img src='smileys/sad_smile.gif'>")
smiles = Replace(smiles, "[wink]", "<img src='smileys/wink_smile.gif'>")
smiles = Replace(smiles, "[sarcastic]", "<img src='smileys/sarcastic.gif'>")
smiles = Replace(smiles, "[shades]", "<img src='smileys/shades.gif'>")
smiles = Replace(smiles, "[what]", "<img src='smileys/what_smile.gif'>")
smiles = Replace(smiles, "[sick]", "<img src='smileys/sick.gif'>")
smiles = Replace(smiles, "[sleepy]", "<img src='smileys/sleepy.gif'>")
smiles = Replace(smiles, "[grin]", "<img src='smileys/teeth_smile.gif'>")
smiles = Replace(smiles, "[thinking]", "<img src='smileys/thinking.gif'>")
smiles = Replace(smiles, "[tongue]", "<img src='smileys/tongue_smile.gif'>")


smileFilter = smiles
End Function

Public Function swearFilter(ByVal swears As String) As String

Dim strSQL as String = "SELECT badword, replacement FROM badwords"
Dim objConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(str1)
Dim ObjCommand As New SqlCommand(strSQL, objConnection)
Dim objDataReader As SqlDataReader

objConnection.Open()
objDataReader = objCommand.executeReader()

While objDataReader.Read()
swears = Replace(swears, objDataReader("badword").ToString, objDataReader("replacement").ToString)
End While

objDataReader.close()
objConnection.Close()

swearFilter = swears
End Function

Public Function FormatStr(ByVal MessageString As String) As String
MessageString = Replace(MessageString, CHR(13), "")
MessageString = Replace(MessageString, CHR(10) & CHR(10), "</P><P>")
MessageString = Replace(MessageString, CHR(10), "<br>")
FormatStr = MessageString
End Function

Public Function EmailFunction(ByVal EmailExists As String) As String
If NOT EmailExists = "" Then
Return "<a href=""mailto:" & EmailExists & """><img src=""smileys/mail.gif"" width=""14"" height=""10"" border=""0"" /></a>"
End If
End Function

</script>

<script runat="server">

'Dim str1 As String = ConfigurationManager.AppSettings("MSSQLConnectionString")

Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
If (Page.IsValid)
' using .Replace("'", "") to remove naughty single quote
Dim sName As String = Server.HtmlEncode(txtName.Text.Replace("'", ""))
Dim sEmail As String = Server.HtmlEncode(txtEmail.Text.Replace("'", ""))
Dim sMessage As String = Server.HtmlEncode(txtMessage.Text.Replace("'", ""))

Dim objConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(str1)
Dim objCmd As SqlCommand
Dim strSQL As String = "INSERT INTO messages (name, email, message) VALUES ('" & sName & "', '" & sEmail & "', '" & sMessage & "')"

'objConnection = New OleDbConnection(strConnection)
objConnection.Open()

objCmd = New SqlCommand(strSQL, objConnection)
objCmd.ExecuteNonQuery()

objConnection.Close()
'Response.Redirect("guestbook.aspx")
bindGrid()

Else
Exit Sub
End If
End Sub
</script>


<%--<script language="JavaScript">
var bodytext = "";
function AddText(NewCode) {
var dob = document.formSign.txtMessage
if (dob.createTextRange && dob.caretPos) {
var caretPos = dob.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
}
else if (dob.setSelectionRange) {
dob.value = dob.value.substring(0,dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd,dob.value.length);
}
else {
dob.value += NewCode;
}
dob.focus();
bodytext = "";
}
</script>--%>


<asp:DataGrid id="viewGrid" runat="server" HorizontalAlign="Center" CellPadding="5" Gridlines="none" HeaderStyle-Font-Bold="True" HeaderStyle-HorizontalAlign="Center" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanged="viewGrid_Paged">
<PagerStyle mode="NumericPages" position="Bottom" Font-Size="X-Large" Font-Bold="true" ForeColor="Red"></PagerStyle>
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<%=strGuestBookName%><p>
</HeaderTemplate>
<ItemTemplate>
<table width="550" cellpadding="2" cellspacing="0" border="0">
<tr bgcolor="<%=strMessageSurround%>">
<td colspan="2">
<%# Container.DataItem("TheDate")%></td>
</tr>
<tr bgcolor="<%=strMessageMiddle%>">
<td colspan="2">
<%# smileFilter(swearFilter(FormatStr(Container.DataItem("message"))))%></td>
</tr>
<tr bgcolor="<%=strMessageSurround%>">
<td width="50%">
<%# EmailFunction(Container.DataItem("email"))%> <%# swearFilter(Container.DataItem("name"))%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

<p></p>
<table>
<tr>
<td align="left"><b>Je Naam:</b><asp:RequiredFieldValidator id="nameReqVal" runat="server" ControlToValidate="txtName" ErrorMessage="Your Name.">*</asp:RequiredFieldValidator></td>
<td align="right"><asp:textbox id="txtName" runat="server"></asp:textbox></td>
</tr>
<tr>
<td align="left"><b>Je E-mail adres:</b><asp:RegularExpressionValidator id="emailRegEx" runat="server" ControlToValidate="txtEmail" ErrorMessage="Your Email." ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator></td>
<td align="right"><asp:textbox id="txtEmail" runat="server"></asp:textbox></td>
</tr>
<tr align="left">
<td colspan="3"><b>Je Bericht:</b><asp:RequiredFieldValidator id="messageReqVal" runat="server" ControlToValidate="txtMessage" ErrorMessage="Your Message.">*</asp:RequiredFieldValidator></td>
</tr>
<tr align="left">
<td colspan="2"><asp:textbox id="txtMessage" runat="server" TextMode="MultiLine" Columns="50" Rows="10"></asp:textbox></td>
<td><table>
<tr>
<td>
<a href="javascript:void(AddText('[angel]'))"><img src="smileys/angel_smile.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[angry]'))"><img src="smileys/angry.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[teeth]'))"><img src="smileys/baring_teeth.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[confused]'))"><img src="smileys/confused.gif" border="0" height="22" width="22" /></a></td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[cry]'))"><img src="smileys/cry.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[dunno]'))"><img src="smileys/dont_know.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[ssh]'))"><img src="smileys/dont_tell.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[haha]'))"><img src="smileys/hahaha.gif" border="0" height="22" width="22" /></a></td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[nerd]'))"><img src="smileys/nerd.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[omg]'))"><img src="smileys/omg.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[party]'))"><img src="smileys/party.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[red]'))"><img src="smileys/red.gif" border="0" height="22" width="22" /></a></td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[smile]'))"><img src="smileys/regular_smile.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[rolleyes]'))"><img src="smileys/roll.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[sad]'))"><img src="smileys/sad_smile.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[wink]'))"><img src="smileys/wink_smile.gif" border="0" height="22" width="22" /></a></td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[sarcastic]'))"><img src="smileys/sarcastic.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[shades]'))"><img src="smileys/shades.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[what]'))"><img src="smileys/what_smile.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[sick]'))"><img src="smileys/sick.gif" border="0" height="22" width="22" /></a></td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[sleepy]'))"><img src="smileys/sleepy.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[grin]'))"><img src="smileys/teeth_smile.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[thinking]'))"><img src="smileys/thinking.gif" border="0" height="22" width="22" /></a></td>
<td>
<a href="javascript:void(AddText('[tongue]'))"><img src="smileys/tongue_smile.gif" border="0" height="22" width="22" /></a></td>
</tr>
</table>
</td>
</tr>
<tr align="left">
<td colspan="3"><asp:ValidationSummary id="ValSum" runat="server" Width="312px" HeaderText="Corrigeer de volgende foute(n):"></asp:ValidationSummary>
<asp:button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Plaats!"></asp:button></td>
</tr>
</table>
<%-- %></form>--%>

 

Thnx in advanced...

You must sign in to post in the forums. This thread is closed to new posts.