You have the complete program (ASP.net). You must have a file inside the App_Data
folder inside your ASP.net app, In this App your file name "Details.txt" which should be available inside your App_Data
folder.
You have Hidden-field and a paragraph available in your web page. When form loads, at that moment read the data from the text file and populate to the Hidden-field control. And in $(document).ready()
Jquery function populate data to paragraph from Hidden-field.
Your .aspx
page :
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="ReadFromTextFileToTextBoxWebApp._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css" >
.details
{
background-color:Purple;color:yellow;top: 100px;
}
.txtDetails
{
left:150px;width:200px;height:100px;
}
</style>
<script src="Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var data = $("#<%=HiddenField1.ClientID %>").val();
$('#pTextData').text(data);
});
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<div>
<asp:HiddenField ID="HiddenField1" runat="server" />
<p id="pTextData">
</p>
</div>
</asp:Content>
and here is your code behind page :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace ReadFromTextFileToTextBoxWebApp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var data = File.ReadAllText(Server.MapPath("~/App_Data/Details.txt"));
HiddenField1.Value = data.ToString();
}
}
}