The page:
-
<%@ Page Title="" Language="VB" MasterPageFile="~/orca.master" AutoEventWireup="false" CodeFile="gastboek.aspx.vb" Inherits="gastboek" %>
-
<%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
-
<asp:Content ID="Content2" ContentPlaceHolderID="cph" Runat="Server">
-
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
-
<ContentTemplate>
-
<h3>Gastenboek</h3><br />
-
<p>Voeg hieronder een nieuw bericht toe aan het gastenboek:</p>
-
<asp:Button runat="server" ID="btn" Text="Show editor" />
-
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
-
<ContentTemplate>
-
<div class="wrap">
-
<div class="overlay" id="overlayFtb" style="display:none;"></div>
-
<div id="thisFTB" class="popupFtb" runat="server" visible="false">
-
<div class="header2">
-
<asp:label ID="titlelabel" runat="server">Gastenboek.</asp:label>
-
<asp:ImageButton runat="server" ToolTip="Sluiten" ID="btncancel" ImageUrl="~/utilities/images/site/buttons/cancel-032x032.gif" />
-
<div class="clear"></div>
-
</div>
-
<div style="background-color:#9EBEF5; border:solid 2px #1E789A;">
-
<div id="dvonderwerp" style="margin:4px;" runat="server">
-
<asp:label ID="lblonderwerp" runat="server" Text="Je naam:" style="float:left; margin-right:10px; font-weight:bold;"></asp:label>
-
<asp:TextBox ID="txtonderwerp" runat="server" style="float:right; width:360px;"></asp:TextBox>
-
<div class="clear"></div>
-
</div>
-
<div>
-
<CE:Editor ID="Editor1" AutoConfigure="Minimal" Width="100%" ThemeType="Office2007" CustomCulture="nl-NL"
-
AllowPasteHtml="false" EnableContextMenu="false" ShowBottomBar="false" runat="server"></CE:Editor>
-
<asp:Button ID="btnsave" runat="server" Text="Opslaan" style="margin-left:2px;" />
-
</div>
-
</div>
-
</div>
-
</div>
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
</ContentTemplate>
-
</asp:UpdatePanel>
-
</asp:Content>
The Code-behind:
- Partial Class gastboek
- Inherits System.Web.UI.Page
- Public Sub showeditor()
- thisFTB.Visible = True
- Dim strscript As String = AppTools.Misc.GetOverLayScript("overlayFtb")
- ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "str", strscript, False)
- End Sub
- Protected Sub btncancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncancel.Click
- thisFTB.Visible = False
- ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "str", AppTools.Misc.GetOverlayCloseScript, False)
- End Sub
- Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
- Dim returnurl As String = Request.Url.AbsoluteUri
- Dim ipaddress As String
- ipaddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
- If ipaddress = "" Or ipaddress Is Nothing Then
- ipaddress = Request.ServerVariables("REMOTE_ADDR")
- End If
- GuestBookAdd(txtonderwerp.Text, Editor1.Text, ipaddress)
- Response.Redirect(returnurl)
- End Sub
- Sub GuestBookAdd(ByVal afzender As String, ByVal bericht As String, ByVal ip As String)
- Dim conn As New System.Data.OleDb.OleDbConnection(AppTools.SQLInstr.GetConnString("dbgastenboek"))
- conn.Open()
- Dim sql As String = "INSERT INTO tblBerichten (afzender, bericht, ip) " _
- & "VALUES (@afzender, @bericht, @ip)"
- Dim comm As New System.Data.OleDb.OleDbCommand(sql, conn)
- comm.Parameters.AddWithValue("@afzender", afzender)
- comm.Parameters.AddWithValue("@bericht", bericht)
- comm.Parameters.AddWithValue("@ip", ip)
- comm.ExecuteNonQuery()
- conn.Close()
- comm.Dispose()
- conn.Dispose()
- End Sub
- Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
- showeditor()
- End Sub
- End Class
The called functions (gets a javascriptstring based on the browser type):
- Public Shared Function GetOverLayScript(ByVal target As String) As String
-
- Dim strScript As String = String.Empty
-
- If HttpContext.Current.Request.Browser.Type = "IE6" Or HttpContext.Current.Request.Browser.Type = "IE7" Then
-
- strScript = "<script type='text/javascript' language='javascript'>" & _
- "function alertSize() {var myHeight = 0;" & _
- "if (typeof (window.innerHeight) == 'number')" & _
- "{myHeight = window.innerHeight;}" & _
- "else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))" & _
- "{myHeight = document.documentElement.clientHeight;}" & _
- "else if (document.body && (document.body.clientWidth || document.body.clientHeight))" & _
- "{myHeight = document.body.clientHeight;}return myHeight;}" & _
- "try{var mydiv = document.getElementById('overlaytrans');" & _
- "var h = alertSize();" & _
- "var h2 = document.getElementById('wrapper').offsetHeight + 166;" & _
- "if (h <= h2) { mydiv.style.height = h2 + 'px';}" & _
- "else { mydiv.style.height = h + 'px';}" & _
- "document.getElementById('" & target & "').style.height = (h2 - 166) + 'px';" & _
- "document.getElementById('" & target & "').style.display = '';" & _
- "mydiv.style.display = '';document.getElementById('header').style.zIndex='-1';}catch(err){}</script>"
- Else
-
- strScript = "<script language='javascript' type='text/javascript'>" & _
- "function alertSize() {var myHeight = 0;if (typeof (window.innerWidth) == 'number') {myHeight = window.innerHeight;} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {myHeight = document.documentElement.clientHeight;} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {myHeight = document.body.clientHeight;}return myHeight;}" & _
- "var mydiv = document.getElementById('overlaytrans');" & _
- "var h = alertSize();" & _
- "var h2 = document.getElementById('wrapper').offsetHeight + 166;" & _
- "if (h <= h2) { mydiv.style.height = h2 + 'px'; }" & _
- "else { mydiv.style.height = '100%';}" & _
- "mydiv.style.display = '';</script>"
-
- End If
-
-
- Return strScript
-
-
- End Function
-
- Public Shared Function GetOverlayCloseScript() As String
- Dim s As String = "<script language='javascript'>document.getElementById('overlaytrans').style.display = 'none';"
- If HttpContext.Current.Request.Browser.Type = "IE7" Or HttpContext.Current.Request.Browser.Type = "IE6" Then s += "document.getElementById('header').style.zIndex='0';"
- s += "</script>"
- Return s
-
-
-
- End Function