Im trying to create a simple guestbook for my website.
A have created a simple .NET user control and added it to my template. Guestbook posts are stored as child documents to my guestbook node.
Guestbook posts are enumerate using a inline Razor macro in my template.
My user control work fine, and the post document is created and published. The problem is aparently the razor macro is rendered before my user control has added the document, so the new post is visible aften another reload of the guestbook page.
Im running Umbraco 6.0.3/IIS7.5 and MSSQL Express.
Here is my code for user control postback event: Private Sub btnGuestBookFormSubmit_Click(sender As Object, e As EventArgs) Handles btnGuestBookFormSubmit.Click 'validate input Page.Validate("GuestbookForm")
If Not Page.IsValid Then Exit Sub End If
Dim user As New User(0) Dim dt As DocumentType = DocumentType.GetByAlias("GuestbookComment")
'create document Dim doc As Document = Document.MakeNew(Now.ToString("yyyy-MM-dd hh:mm ") + txtGuestBookFormAuthor.Text, dt, user, Node.getCurrentNodeId)
<umbraco:Macro Title="Skriv et indlæg" SubmitButtonText="Opret" SubmitNotice="tak for dit indlæg" Alias="GuestbookForm" runat="server"></umbraco:Macro>
You probably need to make a redirect to the page displaying your guestbook entries in order to get the latest entry shown once it's posted. Otherwise you will need to update the page manually to see the new entry.
So in your VB code above you should finnish with a redirect and all should be good.
Enumerating new nodes in same postback
Hi,
Im trying to create a simple guestbook for my website.
A have created a simple .NET user control and added it to my template. Guestbook posts are stored as child documents to my guestbook node.
Guestbook posts are enumerate using a inline Razor macro in my template.
My user control work fine, and the post document is created and published. The problem is aparently the razor macro is rendered before my user control has added the document, so the new post is visible aften another reload of the guestbook page.
Im running Umbraco 6.0.3/IIS7.5 and MSSQL Express.
Here is my code for user control postback event:
Private Sub btnGuestBookFormSubmit_Click(sender As Object, e As EventArgs) Handles btnGuestBookFormSubmit.Click
'validate input
Page.Validate("GuestbookForm")
If Not Page.IsValid Then
Exit Sub
End If
Dim user As New User(0)
Dim dt As DocumentType = DocumentType.GetByAlias("GuestbookComment")
'create document
Dim doc As Document = Document.MakeNew(Now.ToString("yyyy-MM-dd hh:mm ") + txtGuestBookFormAuthor.Text, dt, user, Node.getCurrentNodeId)
'assign properties
doc.getProperty("author").Value = txtGuestBookFormAuthor.Text
doc.getProperty("comment").Value = txtGuestBookFormComment.Text
doc.getProperty("umbracoNaviHide").Value = True
'save document
doc.Save()
'publish
doc.Publish(user)
'reload cache
Global.Umbraco.library.UpdateDocumentCache(doc.Id)
'show comment submitted notice
pnCommentForm.Visible = False
pnCommentSubmitted.Visible = True
End Sub
And here my template:
<%@ Master Language="C#" MasterPageFile="~/masterpages/Layout.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="Content" runat="server">
<h3><umbraco:Item field="pageName" runat="server" /></h3>
<umbraco:Item field="bodyText" runat="server" /><br /><br />
<umbraco:Macro Title="Skriv et indlæg" SubmitButtonText="Opret" SubmitNotice="tak for dit indlæg" Alias="GuestbookForm" runat="server"></umbraco:Macro>
<umbraco:Macro runat="server" language="cshtml">
@foreach(var comment in Model.Children()) {
<div style="width: 80%; border: solid 1px black; margin-bottom: 10px;">
<div style="float: right;">@comment.CreateDate</div>
<div>Navn: @comment.author</div>
<div style="font-style: italic;">@comment.comment</div>
</div>
}
</umbraco:Macro>
</asp:Content>
Any help is appreciated.
Yours Kim Skotte Larsen
Hi Kim
You probably need to make a redirect to the page displaying your guestbook entries in order to get the latest entry shown once it's posted. Otherwise you will need to update the page manually to see the new entry.
So in your VB code above you should finnish with a redirect and all should be good.
Hope this makes sense.
/Jan
is working on a reply...