FieldValidator causing WebForm Events not to function

FieldValidator causing WebForm Events not to function

Post by David Flis » Tue, 06 Aug 2002 08:55:31



Hello,

I have a web form that includes the following: 1 textbox with a Required
Field Validator, 2 Dropdown boxes and a Button. The first Dropdown box as a
SelectedIndexChanged event that dynamically assigns the values in the 2nd
Dropdown box depending on what the user selected in the first dropdown. When
the page loads the user can select different values in the first dropdown
and then the 2nd. If the user clicks the Button, and there is nothing in the
Textbox, then the RequiredFieldValidator will show an error message.

At this point, for reasons unknown to me, if the user changes the 1st
Dropdown box the SelectedIndexChanged event doesn't fire anymore so the
values in 2nd Dropdown box don't change. I traced the code in the VS.NET
de* and it looks like the SelectedIndexChanged event actually DOES run,
but it has no effect whatsoever.

I hope I have explained my problem properly; any help would be greatly
appreciated!

Thanks,

David Fliss


 
 
 

FieldValidator causing WebForm Events not to function

Post by Gar » Tue, 06 Aug 2002 22:16:59


Hi David,

You have clarified your question very clearly. However, I couldn't
reproduce the same issue. I have tested it absed on the code above, and it
worked as exoected:

Public Class SelectedIndexChanged
    Inherits System.Web.UI.Page
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents RequiredFieldValidator1 As
System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents DropDownList2 As
System.Web.UI.WebControls.DropDownList

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.De*StepThrough()> Private Sub
InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not IsPostBack Then
            Dim myItem As ListItem
            With DropDownList1
                myItem = New ListItem()
                myItem.Text = "111"
                myItem.Value = "111"
                .Items.Add(myItem)
                myItem = Nothing

                myItem = New ListItem()
                myItem.Text = "222"
                myItem.Value = "222"
                .Items.Add(myItem)
                myItem = Nothing

                myItem = New ListItem()
                myItem.Text = "333"
                myItem.Value = "333"
                .Items.Add(myItem)
            End With
        End If
    End Sub

    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
        DropDownList2.Items.Clear()
        DropDownList2.Items.Add(DropDownList1.SelectedItem.Value)

    End Sub
End Class

Please post here your code for further troubleshooting.

Gary

This posting is provided "AS IS", with no warranties, and confers no
rights. Enjoyed ASP.NET? http://www.veryComputer.com/

 
 
 

FieldValidator causing WebForm Events not to function

Post by Martin Deche » Wed, 07 Aug 2002 01:50:43


Hi, David,

From what I've seen from your problem is that you need to be able to
populate the second DDL with the default selected index of the first one, so
I can suggest you two solutions:

1) Populate the second DDL on the page_load just like you populate the first
one (of course, using the appropriate logic)

or

2) On the page_load populate a "blank" item (and set it selected) in the
first DDL and disable the button (and the textbox if you want). Then on the
event handler SelectedIndexChanged remove the "blank" item from the first
DDL, enable the button (and the textbox) and apply the logic to the second
DDL.

Hope this will help you
Marty

> Thank you for your responce Gary. I used the code you provided and I am
> still encountering the same error. In addition to the code you provided I
> set the dropdownlist1 autopostback = true.

> The only way I can get your code or my code to work is if I set the
> RequiredFieldValidator1.EnableClientScript = False.  I will attach the
> complete code that i used to this message.

> Thanks,
> David Fliss


 
 
 

1. Passing object into ActiveX function causes error in C++ but not C#

Hi,

I am using a ActiveX component that I put through the type converter.

A function I need to use takes a VARIANT as a parameter.
In C# I pass the data in and the function runs fine. In C++  the data is
rejected as invalid.

In C# I am constructing the data as follows. I think it looks wrong but this
was the only way to get it to work.

Object[] objarray = new Object[5];

objarray [0] = 0x00;
objarray [1] = 0xA4;
objarray [2] = 0x04;
objarray [3] = 0x00;
objarray [4] = 0x0E;

comobj->Send(...., objarray , ....);

In C++ it won't let me do this. So I do:

Byte[] bytearray = new Byte[5]

bytearray [0] = 0x00;
bytearray [1] = 0xA4;
bytearray [2] = 0x04;
bytearray [3] = 0x00;
bytearray [4] = 0x0E;

comobj->Send(...., bytearray , ....);

So I suppose the questions I have are:
- What's the difference between the two?
- How can I make C++ marshal the data like C# is doing?

Thanks in advance,

James

2. Must one recreate DW after revising Query? (newbie asking)

3. toolbar not causing validation events to fire

4. More Information for MFM Drives

5. NAT causes Remoting events to fail & Bidirectional TCP not working

6. PGP disk: Backing up .pgd - files

7. Why webform buttons within table elements do not fire events

8. How to specify the from-tag for different users on a multi-domain-system ?

9. Need help - Clone function causes exception

10. FieldValidator Javascript

11. Bypassing FieldValidator

12. FieldValidator

13. calling a simple javascript function from a webform control