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 8307503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:32:19+00:00 2026-06-08T18:32:19+00:00

Am really enjoying my learning experience with ASP.NET with C# so far :). I

  • 0

Am really enjoying my learning experience with ASP.NET with C# so far :). I am just having trouble understanding the IsPostBack function with respect to my code implementation. I have seen a few questions on here about IsPostBack but am after more “generalised” advice for my particular implementation.

The application is relatively simple – you select a font from a dropdown menu and type in some text in a textbox. When you press display, your text displays according to the font option you chose. I have got this working just fine, it is trying to implement the IsPostBack feature so when I try entering something else in the textbox, the text from the previous submission is not shown. I’ve tried changing where my FontsList() method is called from but that does not work – I get a Null Reference error (I know why).

Here is the “code-behind”/C# code I have compiled:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{

    List<String> folderNames;
    List<String> filePrefixes;
    List<String> fileSuffixes;

    protected void FontsList()
    {


        folderNames = new List<String> {"cartoon", "copperDeco", "decoTwoTone", "embroidery", "fancy", "goldDeco", "green",
                                        "greenChunky", "ice", "letsFaceIt", "lights", "peppermintSnow", "polkadot", "rainbow", "seaScribe",
                                        "shadow", "snowflake", "teddy", "tiger", "Victorian", "water", "wood", "zebra"};

        filePrefixes = new List<String> {"alphabet_" + "", "copperdeco-", "", "embroidery-", "art_", "golddeco-", "", "109", "ice",
                                         "faceoff-", "", "peppermint-", "polkadot-", "", "", "shad_", "snowflake-", "alphabear", "", "vic",
                                         "wr_", "wood", "zebra-"};

        fileSuffixes = new List<String> {"s", "", "4", "", "", "", "", "", "", "", "1", "", "", "", "", "", "", "" + "smblue", "",
                                         "", "", "", ""};


    }

    protected void Page_Load(object sender, EventArgs e)
    {
        FontsList();
        if (!IsPostBack)
        {
            //FontsList();
            foreach (String s in folderNames)
            {
                DropDownList.Items.Add(s);
            }
        }

    }

    protected void submitDisplay_Click(object sender, EventArgs e)
    {
        int index = folderNames.IndexOf(DropDownList.Text); //drop down box

        foreach (Char c in textBox.Text)
        {
            if(c == ' ')
            {
                displayText.InnerHtml += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            else
            {
            displayText.InnerHtml += "<img src = 'Alphabets/" + folderNames[index] + "/" + filePrefixes[index] + c + fileSuffixes[index] + ".gif' />";
            }
        }
    }
}

Unfortunately I don’t have access to s server that has ASP.NET features, but am happy to send files etc if need be.

Anyone’s help/feedback is very much appreciated, as always :).

  • 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-06-08T18:32:20+00:00Added an answer on June 8, 2026 at 6:32 pm

    In ASP .NET, the controls automatically store their state in the ViewState object. When the page is posted back, the displayText control still has it’s value from the previous click, and your are appending the new images to it. You need to clear the previous data before appending the new values:

    protected void submitDisplay_Click(object sender, EventArgs e)
    {
        displayText.InnerHtml = "";
    
        int index = folderNames.IndexOf(DropDownList.Text); //drop down box
    
        foreach (Char c in textBox.Text)
        {
            if(c == ' ')
            {
                displayText.InnerHtml += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            else
            {
                displayText.InnerHtml += "<img src = 'Alphabets/" + folderNames[index] + "/" + filePrefixes[index] + c + fileSuffixes[index] + ".gif' />";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know a bunch of people that are really enjoying the improvements that ASP.NET
I'm currently learning WPF. I really am enjoying it so far. I love how
I've just started using jquery and I'm really enjoying using selectors. It occurs to
I'm pretty new to java and really enjoying learning about it. I have made
I'm enjoying Asp.Net MVC and am looking to use it in an upcoming project.
So far I've been enjoying using CodeIgniter to create some simple web apps (really
Really enjoying the stanford iphone course videos, just wondering if there are others out
I'm really enjoying Bottle so far, but the fact that I have to CTRL+C
Really simple but just not getting it. I want to reference a view by
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return

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.