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

  • Home
  • SEARCH
  • 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 6470241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:05:12+00:00 2026-05-25T06:05:12+00:00

I am attempting to fill in an ASP.NET page textbox with some predefined text

  • 0

I am attempting to fill in an ASP.NET page textbox with some predefined text so that when it is displayed the value is predefined. I have tried

protected void Page_PreRender ()
{
    mytextbox.Text = somestring;
}

which works fine in the development environment but on the server produces…

System.NullReferenceException: Object reference not set to an instance of an object

The same applies when I try this in Page_Load. As I read the answers to this question, what I am trying should work (in at least one of these places).

Can anyone see what I am doing wrong?

EDIT more code, as suggested. The C# looks like this:-

    protected void Page_PreRender (Object sender, EventArgs e)
    {
        try
        {
            string [] file_list;
            int i = 0;

            file_list = Directory.GetFiles(MyProg.Common.GetDirectory(),
                                           MyProg.Common.GetFileNameRoot() + "*.*");

            foreach (string filename in file_list)
            {
                string filenameonly = Path.GetFileName (filename);

                if (filenameonly == MyProg.Common.GetFileNameRoot() + "runlog.log")
                {
                    nametextbox.Text = filenameonly;
                }

            }

        }
        catch (Exception ex)
        {
            string mystring = ex.ToString();
            errorMessage.Text = "Page Load Error : " + mystring;
        }

    }

and the ASP.NET page like this…

<%@ Page Language="C#"
         AutoEventWireup="true"
         CodeBehind="MyDialogue.aspx.cs"
         Inherits="MyDialogue" %>
<%@ Register assembly="ComponentArt.Web.UI"
             namespace="ComponentArt.Web.UI"
             tagprefix="ComponentArt" %>
<%@ Register assembly="ComponentArt.Web.Visualization.Charting"
             namespace="ComponentArt.Web.Visualization.Charting"
             tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body>
<form id="myForm" runat="server">
<div style="visibility:hidden">
<asp:TextBox ID="nametextbox"
             TextMode="MultiLine"
             runat="server"
             Visible="true" />
</div>
</form>
</body>
</html>
  • 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-25T06:05:13+00:00Added an answer on May 25, 2026 at 6:05 am

    There could be several areas that are causing this problem. How are you sure that you’ve narrowed it down to the textbox itself? Was this code completely bug-free before adding the textbox message? I’ll post your code below with where I think potential null references may be occurring (in comments):

    string [] file_list;
    int i = 0;
    
    file_list = Directory.GetFiles(MyProg.Common.GetDirectory(),
                                   MyProg.Common.GetFileNameRoot() + "*.*");
    
    // it is possible that file_list is null
    // potentially due to an invalid path (missing / perhaps?)
    foreach (string filename in file_list)
    {
        string filenameonly = Path.GetFileName (filename);
    
        // It's possible that the MixedZone.Kernel.Common library
        // is experiencing the null reference exception because it
        // may not understand what file to get the name root of or 
        // maybe it is not capable of getting the root for some
        // other reason (permissions perhaps?)
        if (filenameonly == MixedZone.Kernel.Common.GetFileNameRoot() + "runlog.log")
        {
            nametextbox.Text = filenameonly;
        }
    

    Some possible solutions or safer code:

    string [] file_list;
    int i = 0;
    
    file_list = Directory.GetFiles(MyProg.Common.GetDirectory(),
                                   MyProg.Common.GetFileNameRoot() + "*.*");
    
    if (file_list == null) throw new Exception("File List is null. Something is wrong.");
    
    foreach (string filename in file_list)
    {
        string filenameonly = Path.GetFileName (filename);
    
        string fileroot = MixedZone.Kernel.Common.GetFileNameRoot();
        if(string.IsNullOrEmpty(fileroot) throw new Exception("MixedZone Library failed.");
    
        if (filenameonly.Equals(fileroot + "runlog.log", StringComparison.OrdinalIgnoreCase)) // Choose your own string comparison here
        {
            nametextbox.Text = filenameonly;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to fill some text with a gradient-fill, where by I set
Attempting a beginner's tutorial. I have the following in my head: <script type=text/javascript charset=utf-8
I am attempting to test some code that uses Request.Item(key) but I can not
I have 10 transact SQL scripts that each create a table and fill it
So I'm attempting to create a report that is able to pre-fill a government
Using the code below, I am attempting to fill a Canvas with UIElements and
Attempting to make a NSObject called 'Person' that will hold the login details for
Attempting/struggling to get registration and sign-up working within an active admin project. I have
I have a class with a static std::map member variable that maps char s
I'm attempting to use 'jQuery Validate' on a form that requires an email address

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.