Hello, I finally managed to create a custum guestbook. I succesfully runned it locally on my computer.
Also i downloaded new mojoportal source code and tried there my custom guestbook-code, it worked fine!
I now uploaded my custom compiled package to my online website. I ran setup in my webpage. My guestbook was showing up within the features-menu. I added it to my page and it works fine. I can post messages to my guestbook and i can see them.
The only problem is the paging. Locally on my computer it works great, but online my guestbook-messages don't show up. The error-log from my website shows no errors. What is wrong?
This is my code:
namespace HvN.Web.Ui
{
public partial class GuestbookModuleModule : SiteModuleControl
{
// FeatureGuid 806bc73c-f1cc-45b2-af4d-cee989976b59
#region OnInit
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new EventHandler(Page_Load);
MyDataGrid.PageIndexChanged += new DataGridPageChangedEventHandler(MyDataGrid_Page);
btnSubmit.Click += new EventHandler(this.btnSubmit_Click);
}
#endregion
//string strMessageSurround, strMessageMiddle, strGuestBookName;
protected void Page_Load(object sender, EventArgs e)
{
LoadSettings();
PopulateLabels();
PopulateControls();
if (!Page.IsPostBack) { bindGridhans(); }
}
private void PopulateControls()
{
TitleControl.EditUrl = SiteRoot + "/GuestbookModule/GuestbookModuleEdit.aspx";
TitleControl.Visible = !this.RenderInWebPartMode;
if (this.ModuleConfiguration != null)
{
this.Title = this.ModuleConfiguration.ModuleTitle;
this.Description = this.ModuleConfiguration.FeatureName;
}
}
private void PopulateLabels()
{
TitleControl.EditText = "Edit";
}
private void LoadSettings()
{
captcha.ProviderName = siteSettings.CaptchaProvider;
captcha.Captcha.ControlID = "captcha" + ModuleId;
captcha.RecaptchaPrivateKey = siteSettings.RecaptchaPrivateKey;
captcha.RecaptchaPublicKey = siteSettings.RecaptchaPublicKey;
}
void bindGridhans()
{
string strSQL = "SELECT id, name, message, TheDate FROM messages ORDER BY TheDate DESC;";
SqlConnection objConnection = new SqlConnection(ConfigurationManager.AppSettings["MSSQLConnectionString"]);
SqlDataAdapter objAdapter = new SqlDataAdapter(strSQL, objConnection);
DataSet objDataSet = new DataSet();
objAdapter.Fill(objDataSet, "messages");
DataView objDataView = new DataView(objDataSet.Tables["Messages"]);
MyDataGrid.DataSource = objDataView;
MyDataGrid.DataBind();
}
void MyDataGrid_Page(object sender, DataGridPageChangedEventArgs e)
{
MyDataGrid.CurrentPageIndex = e.NewPageIndex;
bindGridhans();
}
void btnSubmit_Click(object sender, EventArgs e)
{
Page.Validate();
if (!Page.IsValid) { return; }
// using .Replace("'", "") to remove naughty single quote
string sName = Server.HtmlEncode(txtName.Text.Replace("\'", ""));
string sEmail = Server.HtmlEncode("Niks".Replace("\'", ""));
string sMessage = Server.HtmlEncode(txtMessage.Text.Replace("\'", ""));
SqlConnection objConnection = new SqlConnection(ConfigurationManager.AppSettings["MSSQLConnectionString"]);
SqlCommand objCmd;
string DateTime;
// Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nl-NL")
DateTime = System.DateTime.Now.ToString("M-dd-yyyy HH:mm:ss:fff");
string strSQL = ("INSERT INTO messages (name, email, message, thedate) VALUES (\'"
+ (sName + ("\', \'"
+ (sEmail + ("\', \'"
+ (sMessage + ("\', \'"
+ (DateTime + "\')"))))))));
objConnection.Open();
objCmd = new SqlCommand(strSQL, objConnection);
objCmd.ExecuteNonQuery();
objConnection.Close();
// Response.Redirect("guestbook.aspx")
bindGridhans();
}
public string smileFilter(string smiles)
{
smiles = smiles.Replace("[angel]", "<img src=\'smileys/angel_smile.gif\'>");
smiles = smiles.Replace("[angry]", "<img src=\'smileys/angry.gif\'>");
return smiles;
}
public string swearFilter(string swears)
{
string strSQL = "SELECT badword, replacement FROM badwords";
SqlConnection objConnection = new SqlConnection(ConfigurationManager.AppSettings["MSSQLConnectionString"]);
SqlCommand ObjCommand = new SqlCommand(strSQL, objConnection);
SqlDataReader objDataReader;
objConnection.Open();
objDataReader = ObjCommand.ExecuteReader();
while (objDataReader.Read())
{
//swears = swears.Replace(objDataReader["badword"].ToString, objDataReader["replacement"].ToString);
}
objDataReader.Close();
objConnection.Close();
return swears;
}
}
}
<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="Guestbookandsign_ascx.ascx.cs" Inherits="HvN.Web.Ui.GuestbookModuleModule" %>
<%--<portal:OuterWrapperPanel ID="pnlOuterWrap" runat="server">--%>
<mp:CornerRounderTop id="ctop1" runat="server" />
<%--<portal:InnerWrapperPanel ID="pnlInnerWrap" runat="server" CssClass="panelwrapper GuestbookModule">--%>
<portal:ModuleTitleControl EditText="Edit" EditUrl="~/GuestbookModule/GuestbookModuleEdit.aspx" runat="server" id="TitleControl" />
<%--<portal:OuterBodyPanel ID="pnlOuterBody" runat="server">
<portal:InnerBodyPanel ID="pnlInnerBody" runat="server" CssClass="modulecontent">--%>
<script type="text/javaScript">
var bodytext = "";
function AddText(NewCode) {
var dob = document.getElementById('<%= txtMessage.ClientID %>');
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="MyDataGrid" runat="server" PageSize="10" HorizontalAlign="Center" CellPadding="5" Gridlines="none" HeaderStyle-Font-Bold="True" HeaderStyle-HorizontalAlign="Center" AutoGenerateColumns="false" AllowPaging="True" >
<PagerStyle mode="NumericPages" position="Bottom" HorizontalAlign="Center" Font-Size="X-Large" ForeColor="Red"></PagerStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<table width="550" cellpadding="2" cellspacing="0" border="0">
<tr bgcolor="#c9c19f">
<td colspan="2">
<%# ((System.Data.DataRowView)Container.DataItem)["TheDate"] %></td>
</tr>
<tr bgcolor="#f4f0e2">
<td colspan="2">
<%# smileFilter(String.Format("{0}", DataBinder.Eval(Container.DataItem, "message")))%>
</tr>
<tr bgcolor="#c9c19f">
<td width="50%">
<%# ((System.Data.DataRowView)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="Je naam.">*</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="Je bericht?!.">*</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></td>
</tr>
</table>
<%--<asp:button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Plaats!"></asp:button></td>--%>
<asp:button id="btnSubmit" runat="server" Text="Plaats!"></asp:button>
<tr>
</tr>
<mp:CaptchaControl ID="captcha" runat="server"></mp:CaptchaControl>
<%--</portal:InnerBodyPanel>
</portal:OuterBodyPanel>--%>
<%--<portal:EmptyPanel id="divCleared" runat="server" CssClass="cleared" SkinID="cleared"></portal:EmptyPanel>--%>
<%--</portal:InnerWrapperPanel>
<mp:CornerRounderBottom id="cbottom1" runat="server" />
</portal:OuterWrapperPanel>--%>