TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Asyraf MN
NA
28
7.6k
How to implement/validate IsPostBack on Page_Load?
Mar 13 2018 2:11 AM
public
partial
class
_Default : System.Web.UI.Page
{
private
Random random =
new
Random();
private
string testFilePath = @
"C:\Users\Nor Asyraf Mohd No\Documents\TestFile.txt"
;
private
List<string> testFileLines;
protected
void
Page_Load(object sender, EventArgs e)
{
if
(!File.Exists(testFilePath))
{
Response.Write($
"The file does not exist: {testFilePath}"
);
}
else
{
try
{
testFileLines = File.ReadAllLines(testFilePath).ToList();
}
catch
(Exception ex)
{
Response.Write($
"Could not read file {testFilePath}. Exception details: {ex}"
);
}
}
}
protected
void
Button1_Click(object sender, EventArgs e)
{
if
(testFileLines != null && testFileLines.Count > 0)
{
var randomLine = testFileLines[random.Next(testFileLines.Count)];
Label1.Text = randomLine;
testFileLines.Remove(randomLine);
}
}
}
Reply
Answers (
2
)
dropdownlist help
ViewBag List Into ASP.NET MVC View