Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2003, 12:15 PM
Authorized User
 
Join Date: Oct 2003
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Default RegisterClient

Hi,

I have a dropdownlist in vb.net (server controls). Based on the user's selection from the list of items certain textboxes have to be disabled. I wrote a code but it only seems to work once the page is loaded (which is also what i need). I need it to work also after the page is loaded and a user selects an item.
I tried putting the code also in Private Sub List1_SelectedIndexChanged but it doesn't work

This is my code in codebehind (aspx.vb):
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 Page.IsPostBack Then
            Dim li As New ListItem()
            Dim cities(3) As String
            cities(0) = "Pretoria"
            cities(1) = "JHB"
            cities(2) = "Benoni"
            Dim i As Integer
            For i = 0 To UBound(cities) - 1
                List1.Items.Add(cities(i))

            Next


        End If

 RegisterStartupScript("start", _
    "<script>disableTextBox ();</script>")

    End Sub

 _______________________________
The code in aspx:

<script language="javascript">
    function disableTextBox()

{

   strSelectedItem = document.Form1.List1.options[document.Form1.List1.selectedIndex].text

    if(strSelectedItem == "Pretoria")

    {

        document.Form1.Text1.disabled=true;
         document.Form1.txt2.disabled =false;

    }

    else if(strSelectedItem == "Benoni")

    {

       document.Form1.txt2.disabled = true;
       document.Form1.Text1.disabled=false;
    }

}
        </script>
    </HEAD>


 
Old December 1st, 2003, 01:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Somehow, this questions seems to be the same as Peter and I answered yesterday (http://p2p.wrox.com/topic.asp?TOPIC_ID=7039)

Peter answer this:

Quote:
quote:However, you can't immediately do what Imar is suggesting through the obvious ASP.net facilities. Certainly not in the ASPX markup. What you probably will need to do is add a line to your page code that modifies the onchange attribute so the client side javascript call will show up in the select tag.

drpCPay.Attributes.Item("onChange") = "List1_Changed()"
This will add an onchange handler (client side) that calls List1_Changed() when the user makes a new selection in the drop down list.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.