472,341 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,341 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 1268
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...
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....
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...
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...
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...
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...
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()...
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...
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...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.