views:

61

answers:

3

Hi all, I am trying to polish up a program a program that I have converted from a Windows Form in to an ASP.NET Web Application. I have several questions:

1.) I have a drop down box where users can select their variables, but users can also enter their variables manually into various text fields. What I want is for the drop down box to show a string like "Choose Variables" when ever the user enters their variables manually. I want this to happen without having to reload the page.

2.) In the Windows Form version of this application I had a RichTextBox that populated with data (line by line) after a calculation was made. I used "AppendText" in my Windows Form, but that is not available in ASP.NET, and neither is the RichTextBox. I am open to suggestions here, I tried to use just a text box but that isn't working right.

3.) In my Windows Form application I was using "KeyPress" events to prevent incorrect characters from being entered into the text fields. My code for these events looked similar to this:

Private Sub TextBox_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox.KeyPress

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
            e.Handled = True
        End If

End Sub

How can I make this work again... also without reloading the page.

4.) This is not a major issue, but I would like all of the text to be selected when the cursor enters a field. In my Windows Form application I used "SelectAll", but again, that is not available in ASP.NET

Thanks in advanced.

+2  A: 

You need to learn Javascript.

You should read a good book about it; asking us to write all of your Javascript code without learning the language is not a good idea.

SLaks
Javascript? I think you read my question wrong. I am not asking for you to write my code either, I just don't know many ASP.NET functions, thus I am having trouble porting my Windows Form application correctly. Additionally, I have most of it working myself thank you very much. As I stated in my question, I am looking to polish it up a bit. Here I was thinking SO was the place to ask these types of questions.
typoknig
Trust me; you do need to learn Javascript.
SLaks
ASP.Net code runs in the server and cannot run without a postback (or AJAX callback). In order to control behavior or run code in the browser, you _need_ to use Javascript.
SLaks
Ok, that makes more sense than just saying "You need to learn Javascirpt". I do recall seeing some AJAX functions in the toolbox. I will investigate those here real quick.
typoknig
AJAX is the wrong thing to use here and will result in a slow and unresponsive site. You _do_ need to use Javascript.
SLaks
SLaks is right you really need to use javascript using AJAX controls will get you halfway there at best.
Anthony
I have never used either so I will start with Javascript like you guys are suggesting.
typoknig
Cool google "jQuery for ASP.NET Developers" I think this book should get you started.
Anthony
+2  A: 

1) You will have to do this in Javascript by changing the text of the dropdown or disabling it from the TextChanged event using something like this

2)You can use a Textbox with the TextMode set to MultiLine. Then you can use Textbox1.Text = Textbox1.Text & newString to append text to the end.

3) You can either do this in javascript or by using a regular expression validator (my suggestion).

4) Do this in javascript using something like this

bechbd
Thank you for the examples, it helps.
typoknig
A: 

You need to start looking at client side scripting i.e. javascript. This is the only way I know of to accomplish what you want with out posting back to the server.

There are some great javascript libraries out there: Jquery seems to becoming the defacto standard though. (Some may disagree with the defacto bit.) Jquery has some great example code on there site and lots of information is avaliable on the web. Good Hunting!

Anthony