Hello,
I tried again to run my guestbook. I completely build the user control (*.ascx) up again with help form the developer video's. De user control works without the datagrid for my user control. When i put the code for the datagrid in and my button i get again folowing error:
Guestbook/Guestbookandsign_ascx.ascx
System.Web.HttpCompileException (0x80004005): l:\Documenten\Visual Studio 2010\Projects\MojoPortal-source2\mojoportal_cc7dd5ee32dc\Web\Guestbook\Guestbookandsign_ascx.ascx(125): error CS1061: 'ASP.guestbook_guestbookandsign_ascx_ascx' does not contain a definition for 'btnSubmit_Click' and no extension method 'btnSubmit_Click' accepting a first argument of type 'ASP.guestbook_guestbookandsign_ascx_ascx' could be found (are you missing a using directive or an assembly reference?)
It again has something to do with the events not firing up !!
Does anybody does have any solution?! Its driving me nuts. My guestbook worked before implementing it in the mojoportal solution according to the dev-videos.
All i want is the captcha control to be used in my guestbook, so thats why i created the user-control according to the dev-video's.
PLEASE HELP.
This is my code file:
// Author: Joe Audette
// Created: 2011-7-7
// Last Modified: 2011-7-7
//
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license.
//
// You must not remove this notice, or any other, from this software.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using mojoPortal.Web.UI;
//using log4net;
//using HvN.Features.Business;
using Resources;
using System.Data.SqlClient;
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);
}
#endregion
//string strMessageSurround, strMessageMiddle, strGuestBookName;
protected void Page_Load(object sender, EventArgs e)
{
LoadSettings();
PopulateLabels();
PopulateControls();
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\'>");
smiles = smiles.Replace("[teeth]", "<img src=\'smileys/baring_teeth.gif\'>");
smiles = smiles.Replace("[confused]", "<img src=\'smileys/confused.gif\'>");
smiles = smiles.Replace("[cry]", "<img src=\'smileys/cry.gif\'>");
smiles = smiles.Replace("[dunno]", "<img src=\'smileys/dont_know.gif\'>");
smiles = smiles.Replace("[ssh]", "<img src=\'smileys/dont_tell.gif\'>");
smiles = smiles.Replace("[haha]", "<img src=\'smileys/hahaha.gif\'>");
smiles = smiles.Replace("[nerd]", "<img src=\'smileys/nerd.gif\'>");
smiles = smiles.Replace("[omg]", "<img src=\'smileys/omg.gif\'>");
smiles = smiles.Replace("[party]", "<img src=\'smileys/party.gif\'>");
smiles = smiles.Replace("[red]", "<img src=\'smileys/red.gif\'>");
smiles = smiles.Replace("[smile]", "<img src=\'smileys/regular_smile.gif\'>");
smiles = smiles.Replace("[rolleyes]", "<img src=\'smileys/roll.gif\'>");
smiles = smiles.Replace("[sad]", "<img src=\'smileys/sad_smile.gif\'>");
smiles = smiles.Replace("[wink]", "<img src=\'smileys/wink_smile.gif\'>");
smiles = smiles.Replace("[sarcastic]", "<img src=\'smileys/sarcastic.gif\'>");
smiles = smiles.Replace("[shades]", "<img src=\'smileys/shades.gif\'>");
smiles = smiles.Replace("[what]", "<img src=\'smileys/what_smile.gif\'>");
smiles = smiles.Replace("[sick]", "<img src=\'smileys/sick.gif\'>");
smiles = smiles.Replace("[sleepy]", "<img src=\'smileys/sleepy.gif\'>");
smiles = smiles.Replace("[grin]", "<img src=\'smileys/teeth_smile.gif\'>");
smiles = smiles.Replace("[thinking]", "<img src=\'smileys/thinking.gif\'>");
smiles = smiles.Replace("[tongue]", "<img src=\'smileys/tongue_smile.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="true" 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">
<div class="settingrow">
This will soon be the entry point to the GuestbookModule.<br />
</div>
<mp:CaptchaControl ID="captcha" runat="server"></mp:CaptchaControl>
<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="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>
</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>