473,728 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please help, changing the value problem

3 New Member
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 1340
dorinbogdan
839 Recognized Expert Contributor
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
1590
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 seems to get me any closer to the solution. Below is a program that I am working on for a class project. The original code was provided for us which is what I have below. What we have to do is make the app run so that it allows the user to add...
11
1922
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 this HTML file, all is OK but whenever the functions are separated (as it is now), when I run the page, I get the following error: Line 73, object expected.
2
3401
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. After parsing the text we are using the following methods for setting the color of the text. RichText.Select(int startIndex, int length) & RichText.SelectionColor = Color.Red
6
1431
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 = 'Dani'). the problem is that i don't understanh how the ViewRowState works: i have an external form that changes the value of the dataTable.
0
1231
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? The following code is a complete page that demonstrates my problem. If you save this as an .aspx and load it in a browser, it tells you it is creating the cookie. If you reload the page, it tells you it is changing the value. If you reload it...
4
2470
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, as I expected. I haven't seen this behavior explained precisely in the .net world yet, so I wanted to check and make sure I've got it right. I apologize that this is a bit long. I've tried to keep it concise. There are code fragments here, but...
1
7406
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) However, xmlhttp.responseTest can NOT be assigned to a normal string variable, UNLESS the file is already present in the temporary internet folder. This problem only occurs in the remote webserver context, not on my local system. It seems that a...
1
54520
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 we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if applicable.
5
2560
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 use to run a UM program, I kept on getting error messages. I have used someone else's implementation and it runs fine. I have compared my code with other's and I still can't figure it out what's wrong with mine. So please help me out, after 3...
1
2177
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 (LoginName,UserName) 2. the datagridview sorting is set to automatic, so when i click on the column header is sorts well. 3. i put in an event handler for the CellEndEdit Event, so whenever the user of the program changes the content of a cell in the LoginName...
0
8759
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9199
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8136
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2671
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2161
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.