reset form - from a total newbie

G

Guest

I've been looking and trying suggestions from here and elsewhere, but I can't
seem to make them work. I'm using VisualStudio.net Development Environment
7.0.9466.

I am trying to duplicate the functionality of a straight html page that I
was given as a mock up.

I have a web form with several textbox input fields and one checkbox. I have
added simple requiredfieldvalidators after the textbox inputs, and a submit
button that seems to correctly display the error message when the text fields
are not filled in.

I want to be able to add a reset button as well.

I added a button control, similar to the way I did the submit button, but
made causesValidation false.

I double clicked on the button in the design environment which brought me to
the code behind and the _Click event for the button.

However, when I run the project, either through viewing the page in a
browser or the Solution start button on the toolbar, the new button seems
dead.

As I said, the Submit button I placed in a similar way seems to work fine.

I've tried (after adding an "id" value of form1 to the default form that was
generated by creating the page):
Dim myForm As Control = Page.FindControl("form1")
Dim ctl As Control
For Each ctl In myForm.Controls
If
ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") Then
CType(ctl, TextBox).Text = ""
End If
Next ctl

and also tried explicitly setting the fields, for example:
UserName.Text = ""
where UserName is one of the textbox controls.

I placed a breakpoint on
Private Sub ResetButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ResetButton1.Click
before running it in debug mode, but it didn't seem to ever hit it.
(I'm just developing on localhost)

I also tried, as an experiment
UserName.font.bold = not UserName.font.bold
and msgbox("test")
to see if I could at least get anything out of the button.

I know it was added to the class
Protected WithEvents ResetButton1 As System.Web.UI.WebControls.Button

If I change the causeValidation to true it validates.

It's probably something obvious, but I'm stumped at the moment.

Any help appreciated.

Keith
 
G

Guest

I'm definately missing something simple.

I created a test form page with a label, a textbox and button.

I placed this code in the code behind:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Label1.Text = Label1.Text & "+a"
TextBox1.Text = String.Empty
End Sub

The label adds a "+a" when the button clicks.
The textbox does not clear (I also tried with TextBox1.Text ="")

Any help greatfully and grovingly appreciated.

Keith
 
G

Guest

I have the button working, sort of.

My page has table with a user control header and footer at the top and the
bottom. In a row inbetween are the input elements, and below that in the next
row is the submit and (not working) refresh buttons.

If I put a test button with a textbox at the top of the page (above the
table), I can programaticaly in the code behind set the "text" property of
the textbox by pushing the button ie
UserName.Text = UserName.Text + "-a"

However, if I move the same button into or below the table, no change in the
code behind) it stops working.

Is there something in using user controls or in location vis-a-vis tables
that cause handlers to stop working?

Thanks

Keith
However, if I move the same button below the table
 
G

Guest

Found the problem.

Particularly with designers mock up code, watch out when you're nesting user
controls that they don't have </form> tags in them.

Keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top