473,383 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

please help, changing the value problem

Hello guys, I have this kind of problem:
first, the textBox tbISBN has a value that is read from the text file, but then after pressing the "Clear" button, it should be realized, and when I enter the new text into the textBox it should get the new text that I entered, but it keeps it's first value, even after the "Clear" button event.
Here is the code.

Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page 
  2. {
  3.    private Book selectedBook;
  4.    public string strISBN;
  5.    public string strCurrent;
  6.    public string[] strFields;
  7.    public char[] chrDelimiter = { ',' };
  8.    public SortedList slBook;
  9.    public StreamReader srdCurrent;
  10.  
  11.     public string content;
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.         if (!IsPostBack)
  15.         {
  16.             SortedList slBooks = new SortedList();
  17.  
  18.             StreamReader srdCurrent = new StreamReader(Request.MapPath(@"App_Data\Books.txt"));
  19.  
  20.             strCurrent = srdCurrent.ReadLine();
  21.  
  22.             while (strCurrent != null)
  23.             {
  24.                 Book recNew = new Book();
  25.                 strFields = strCurrent.Split(chrDelimiter);
  26.  
  27.                 recNew.Title = strFields[0];
  28.                 recNew.ISBN = strFields[1];
  29.                 recNew.Author = strFields[2];
  30.                 recNew.Publisher = strFields[3];
  31.                 recNew.UnitPrice = System.Convert.ToDecimal(strFields[4]);
  32.  
  33.                 slBooks.Add(recNew.Title, recNew);
  34.                 strCurrent = srdCurrent.ReadLine();
  35.  
  36.                 // Add the book title to the drop down list
  37.                 ddlBooks.Items.Add(recNew.Title);
  38.             }
  39.  
  40.             // Close the file when reading is complete.
  41.             srdCurrent.Close();
  42.  
  43.             // Add the sorted list to this session 
  44.             Session.Add("Book", slBooks);
  45.  
  46.         }
  47.  
  48.         selectedBook = GetSelectedBook();
  49.         if (selectedBook != null)
  50.         {
  51.            tbTitle.Text = selectedBook.Title;
  52.             tbISBN.Text = selectedBook.ISBN;
  53.             tbAuthor.Text = selectedBook.Author;
  54.             tbPublisher.Text = selectedBook.Publisher;
  55.             tbPrice.Text = selectedBook.UnitPrice.ToString("c");
  56.             imgBook.ImageUrl = "Images/Books/" + selectedBook.ISBN + ".gif";
  57.         }
  58.     }
  59.     private Book GetSelectedBook()
  60.     {
  61.         SortedList slBooks = (SortedList)Session["Book"];
  62.         if (slBooks == null)
  63.             return null;
  64.  
  65.         string strTitle = ddlBooks.SelectedValue;
  66.         return (Book)slBooks[strTitle];
  67.     }
  68.  
  69.  
  70.     //***********************************************************************************
  71.     public void btnClear_Click(object sender, EventArgs e)
  72.     {
  73.         /*selectedBook.Title = "";
  74.         selectedBook.ISBN = "";
  75.         selectedBook.Author = "";
  76.         selectedBook.Publisher = "";
  77.         selectedBook.UnitPrice = 0.00m;*/
  78.         StreamWriter delete = new StreamWriter(Request.MapPath(@"App_Data\Boo.txt"));
  79.  
  80.         tbTitle.Text = "";
  81.         tbISBN.Text = "";
  82.         tbAuthor.Text = "";
  83.         tbPublisher.Text = "";
  84.         tbPrice.Text = "";
  85.         imgBook.ImageUrl = "";
  86.         lblUploadResult.Text = "";
  87.  
  88.     }
  89.     //***********************************************************************************
  90.     protected void AddBook()
  91.     {
  92.         strISBN = tbISBN.Text;
  93.         string filePath = Server.MapPath(@"App_Data\Books.txt");
  94.  
  95.         StreamReader sr = File.OpenText(filePath);
  96.  
  97.         //StreamReader srdCurrent = new StreamReader(Request.MapPath(@"App_Data\Books.txt"));
  98.  
  99.         //StreamWriter rite = new StreamWriter(Request.MapPath(@"App_Data\Boo.txt"));
  100.         //rite.WriteLine("any string");
  101.         //rite.Close();
  102.  
  103.         try
  104.         {
  105.  
  106.             content = sr.ReadToEnd();
  107.             if (content.Contains(strISBN))
  108.             {
  109.                 lblUploadResult.Text = "isbn contained";
  110.                 sr.Close();
  111.             }
  112.             else
  113.             {
  114.                 StreamReader srdCurrent = new StreamReader(Request.MapPath(@"App_Data\Books.txt"));
  115.  
  116.                 StreamWriter rite = new StreamWriter(Request.MapPath(@"App_Data\Boo.txt"));
  117.                 rite.WriteLine("any string");
  118.                 rite.Close();
  119.  
  120.             }
  121.         }
  122.         catch (Exception) { }
  123.  
  124.     }
  125.  
  126.  
  127.  
  128.  
  129.     //**************************************************************************************
  130.  
  131.     protected void btnSave_Click(object sender, EventArgs e)
  132.     {
  133.         AddBook();
  134.     }
  135.  
  136.  
  137. }
  138.  
Thank you very much!
Mar 22 '07 #1
1 1321
dorinbogdan
839 Expert 512MB
Try to assign a char array (char[]) to tbISBN.Text instead of a String.
If still not working, please post or attach the required code to run this part of project.
Mar 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do...
11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
2
by: Catherine Jones | last post by:
Hi all, We are into the development of an application in C#. In one of the module we are using RichEdit control as text editor. This text editor is resposible for highlighting certain keywords....
6
by: Ubi | last post by:
hi i have a problem with System.Data.DataViewRowState. i have a ReadOnly datagrid, a dataView and a dataTable. i'm using the dataView's filter property to filter the data (firstName =...
0
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and byRef, and the results were slightly non-intuitive,...
1
by: KoosJaspers | last post by:
I have a remarkable problem. Opening a file using xmlhttp works perfectly. The responseText output is read, since it can be assigned to an alert() message, as follows : alert(xmlhttp.resposeText)...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.