Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   RegisterClientScript (http://www.velocityreviews.com/forums/t756163-registerclientscript.html)

collie 12-01-2003 04:35 PM

RegisterClientScript
 
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>

Jim Cheshire [MSFT] 12-01-2003 07:56 PM

RE: RegisterClientScript
 
Hi,

The situation you describe does not require RegisterStartupScript. The
only time you would need to generate your client-side script on the server
is if you do not know at design-time what needs to be in your script. In
your case, you already know all of your script when you are designing the
page. Therefore, what you should be doing is putting all of your script in
the ASPX page itself.

To execute the script when the page loads, place the call to the script in
the "onload" of the <body> tag.

To execute the script when you select an item in your ListBox, you just
need to hook the OnSelectedIndexChanged client-side event like so:

<asp:ListBox id="ListBox1" OnSelectedIndexChanged="disableTextBox();" ....

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
jamesche@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
>From: katzavital@hotmail.com (collie)
>Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
>Subject: RegisterClientScript
>Date: 1 Dec 2003 08:35:28 -0800
>Organization: http://groups.google.com
>Lines: 65
>Message-ID: <960316fe.0312010835.5935bf15@posting.google.com >
>NNTP-Posting-Host: 81.218.123.210
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: posting.google.com 1070296528 11513 127.0.0.1 (1 Dec 2003

16:35:28 GMT)
>X-Complaints-To: groups-abuse@google.com
>NNTP-Posting-Date: Mon, 1 Dec 2003 16:35:28 +0000 (UTC)
>Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFT NGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news-spur1.maxwell.syr.edu!
news.maxwell.syr.edu!postnews1.google.com!not-for-mail
>Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.aspnet.buildingc ontrols:8311
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
>
>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>
>




All times are GMT. The time now is 05:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.