Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:50+00:00 2026-05-27T13:14:50+00:00

I have a web part for managing comments related to ongoing promotions. The web

  • 0

I have a web part for managing comments related to ongoing promotions. The web part is hosted in a Sandbox Solution because server access of all kinds is restricted (//sharepoint)

I have two main issues with my code.

1: Items submitted do not appear after postback, leaving user to think their comments was not saved,

2: PostBack data refires after page refresh, meaning if a user refreshes hoping to see their comments, it is re-submitted and saved.

What am I doing wrong here?

public string OfferID { get; set; }
protected void Page_Load(object sender, EventArgs e)
        {
            OfferID = Context.Request.QueryString["ItemID"];
            LoadOffers();
        }

protected void LoadOffers()
        {
            if (!String.IsNullOrEmpty(OfferID))
            {
                PopulateOfferDetails(OfferID);
                PopulateComments(OfferID);
                PopulateBestPractices(OfferID);
            }
            else
            {
                OfferID = "123";
                PopulateOfferDetails(OfferID);
                PopulateComments(OfferID);
                PopulateBestPractices(OfferID);
            }
        }

protected void PopulateComments(string offerID)
    {
        rcOiD.InnerText += " " + offerID;

        List<Comment> Comments = new List<Comment>();
        SPList TargetList = web.Lists.TryGetList("Offer Comments");
        SPQuery query = new SPQuery();
        query.RowLimit = 100;
        query.Query = "<Where><Eq><FieldRef Name=\"OfferID\"/><Value Type=\"Text\">" + offerID + "</Value></Eq></Where>";
        try
        {
            SPListItemCollection items = TargetList.GetItems(query);
            if (items.Count > 0)
            {
                commentsCount.InnerText = items.Count.ToString();
                SPUser user = web.CurrentUser;
                string alias = user.Email.Substring(0, user.Email.IndexOf('@'));
                string profilePicBase = "<div class=\"profilePic\" " + "style=\"background-image:url('http://who/Photos/XX.jpg');\"" + ">&nbsp;</div>";
                foreach (SPListItem item in items)
                {
                    Comment c = new Comment();
                    c.Author = ((string)item["Created By"]).CleanUserName();
                    c.Body = (string)item["Body"];
                    c.Date = String.Format("{0:MMM dd, yyyy}", (DateTime)item["Created"]);
                    c.ProfilePic = profilePicBase.Replace("XX", alias);

                    Comments.Add(c);
                }
                Comments.Reverse();
                CommentRepeater.DataSource = Comments;
                CommentRepeater.DataBind();
            }
            else
            {
                commentsCount.InnerText = "0";
            }
        }
        catch (Exception ex)
        {
        }
    }

protected void SubmitListItem(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                SPUser user = web.CurrentUser;
                string alias = user.Email.Substring(0, user.Email.IndexOf('@'));
                if (ListChoice.SelectedItem.Text == "comment")
                {
                    SPList TargetList = web.Lists.TryGetList("Offer Comments");
                    SPListItem item = TargetList.Items.Add();
                    item["Title"] = TitleBox.Text;
                    item["Body"] = BodyBox.Text;
                    item["OfferID"] = OfferID;
                    item["Alias"] = alias;
                    item.SystemUpdate();
                    TargetList.Update();
                }
                else
                {
                    SPList TargetList = web.Lists.TryGetList("Offer Best Practices");
                    SPListItem item = TargetList.Items.Add();
                    item["Title"] = TitleBox.Text;
                    item["Body"] = BodyBox.Text;
                    item["OfferID"] = OfferID;
                    item.SystemUpdate();
                    TargetList.Update();
                }
            }
        }

EDIT: I can confirm this isn’t a databind() issue. The item.count being pulled on postback is being rendered properly, but is still 1 item short.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:14:51+00:00Added an answer on May 27, 2026 at 1:14 pm

    I assume SubmitListItem is an event handler of an control on the page.
    If that is so then as in your previous question, Page_Load is is fired before any control’s event handler.
    Therefore on postback your repeater is getting bound before the item addition occurs so on that load you do not get to see the new item.
    To prevent this rebind the repeater after item addition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a web part and deployed it on my server using this
I have to create a web part that displays all site collections under the
I have a web part that I have been deploying to Server A. I
I have a web part that saves preferences to an external database because they
We have a web part that uploads a document to a document library. The
I have a web part which uses many SharePoint controls like menu, SPGrid, tool
I have developed a web part that has to be deployed on a Sharepoint
I have requirement of specifying web part connections in onet.xml. So when site is
I have created a SharePoint web part and inside this web part I am
I have web application of which major part is javascript. I request images from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.