Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Joseph Harrison 4 posts 24 karma points
    Feb 20, 2012 @ 22:04
    Joseph Harrison
    0

    User control - strange behaviour

    Hi,

    I have created a simple user control that creates forum topics.......

    The user control works perfectly...... but it only works once...

    for example only lets u create 1 topic.

    if you try and add another topic via the control it just reloads the page with an empty form...

    i have tried attaching to process and debugging and it lets you step through the first time, but when you run it for a second time it doesnt even hit the breakpoint and it just seems like nothing is happening.

    am i doing something wrong?? do i need to change an umbraco setting to allow multiple docs to be created or something??

    please help its driving me crazy lol!

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CreateForumTopic.ascx.cs"
    Inherits="umbracoForum.usercontrols.CreateForumTopic" %>
    <h2>
    create forum topic</h2>
    <div>
    <asp:TextBox runat="server" ID="txtTitle"></asp:TextBox>
    </div>
    <div>
    <asp:TextBox runat="server" ID="txtMessage" TextMode="MultiLine"></asp:TextBox>
    </div>
    <div>
    <asp:Button runat="server" ID="btnCreate" OnClick="btnCreate_Click" Text="create" />
    </div>


    using System;
    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic.web;

    namespace umbracoForum.usercontrols
    {
    public partial class CreateForumTopic : System.Web.UI.UserControl
    {
    public int CurrentPageId { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnCreate_Click(object sender, EventArgs e)
    {
    //Get the Document types
    var topicDocType = DocumentType.GetByAlias("ForumTopic");
    var postDocType = DocumentType.GetByAlias("ForumPost");

    //create a user
    var u = new User(0);

    //create the post title
    string postTitle = txtMessage.Text;
    if (postTitle.Length > 10)
    postTitle = postTitle.Substring(0, 10) + "...";

    //Create the topic document
    var topicDoc = Document.MakeNew(txtTitle.Text, topicDocType, u, CurrentPageId);
    topicDoc.getProperty("topicTitle").Value = txtTitle.Text;
    topicDoc.Publish(u);
    //if (topicDoc.Published)
    umbraco.library.UpdateDocumentCache(topicDoc.Id);

    // create the post doc
    var postDoc = Document.MakeNew(postTitle, postDocType, u, topicDoc.Id);
    postDoc.getProperty("postMessage").Value = txtMessage.Text;
    postDoc.Publish(u);
    //if (postDoc.Published)
    umbraco.library.UpdateDocumentCache(postDoc.Id);

    Response.Redirect(Request.RawUrl);
    }
    }
    }

Please Sign in or register to post replies

Write your reply to:

Draft