|
 |
aspx thread: OnSelectedIndexChanged question
Message #1 by "McCloy, Russell" <Russell.McCloy@B...> on Wed, 6 Mar 2002 08:50:20 +1100
|
|
Hi all,
I have a question relating to the OnSelectedIndexChanged event of a
dropdownlist.
What I need to do is:
when the OnSelectedIndexChanged event fires on my dropdownlist I want a text
box next to my dropdownlist to fill with the text
of the selected item I chose in my drop down list.
To begin with I set it up and the event wouldn't fire so I added the
autopostback=true to my dropdownlist.
This caused the event to fire but no matter what item I selected from my
dropdownlist, only the top (index = 0) item
would be placed in my text box.
I suppose I could add some client side javascript to do this but I don't
want to.
How does one fire client side events?
Thanks in advance,
RuSs
baker & McKenzie.
Web Developer
-----Original Message-----
From: ToddC@m... [mailto:ToddC@m...]
Sent: Wednesday, 6 March 2002 2:12 AM
To: ASP+
Subject: [aspx] RE: Please help me!
I haven't done any graphics work (yet), but I think you need to look at
GDI+. As for mouse events, this sounds like DHTML and is not really what
.NET is about. JavaScript is still interpreted on the client, and any of
the current JavaScripts books should be able to help you out with that.
Sorry not much help, but it didn't sound like you were getting any help.
tc
-----Original Message-----
From: Nguyen Ha Giang [mailto:giang@c...]
Sent: Tuesday, March 05, 2002 2:40 AM
To: ASP+
Subject: [aspx] Please help me!
Dear all,
I'm learning program ASP.NET by C#. Pls teach me how draw 2D on web page,
and manage mouse event on this page. I'm no have any material about problem
and I think MSDM of MS not enough technical material...
Pls help me, thanks!
Nguyen Ha Giang
Message #2 by "Goh Mingkun" <mangokun@h...> on Wed, 6 Mar 2002 01:56:17
|
|
Here is the steps I took to create a sample web application that test this
OnSelectedIndexChanged event:
Add a DropDownList control and a TextBox control onto the web form.
Set AutoPostBack = True for DropDownList1.
Go to View Code.
In the Page_Load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim i As Integer
For i = 1 To 12
DropDownList1.Items.Add(New ListItem(Format(New DateTime
(1800, i, 1), "MMM"), i))
Next
End If
End Sub
In the DropDownList1_SelectedIndexChanged event:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
TextBox1.Text = DropDownList1.SelectedItem.Text
End Sub
That's all, and it works!
Message #3 by "Lewis Bass" <lewis@t...> on Wed, 6 Mar 2002 07:36:23 -0700
|
|
I had a similiar problem - and i think that you are experieancing the same
thing.
When a aspx web page is posted back to the server the page init function
recreates the page. This would wipe out
any input that your user did. You need to change your page init function to
be similiar to the code below
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
<page initializition code here>
end if
end sub
I hope that this helps!
----- Original Message -----
From: "McCloy, Russell" <Russell.McCloy@B...>
To: "ASP+" <aspx@p...>
Sent: Tuesday, March 05, 2002 2:50 PM
Subject: [aspx] OnSelectedIndexChanged question
> Hi all,
>
> I have a question relating to the OnSelectedIndexChanged event of a
> dropdownlist.
> What I need to do is:
>
> when the OnSelectedIndexChanged event fires on my dropdownlist I want a
text
> box next to my dropdownlist to fill with the text
> of the selected item I chose in my drop down list.
>
> To begin with I set it up and the event wouldn't fire so I added the
> autopostback=true to my dropdownlist.
> This caused the event to fire but no matter what item I selected from my
> dropdownlist, only the top (index = 0) item
> would be placed in my text box.
>
> I suppose I could add some client side javascript to do this but I don't
> want to.
>
> How does one fire client side events?
>
> Thanks in advance,
>
> RuSs
>
> baker & McKenzie.
> Web Developer
>
> -----Original Message-----
> From: ToddC@m... [mailto:ToddC@m...]
> Sent: Wednesday, 6 March 2002 2:12 AM
> To: ASP+
> Subject: [aspx] RE: Please help me!
>
>
> I haven't done any graphics work (yet), but I think you need to look at
> GDI+. As for mouse events, this sounds like DHTML and is not really what
> .NET is about. JavaScript is still interpreted on the client, and any of
> the current JavaScripts books should be able to help you out with that.
>
> Sorry not much help, but it didn't sound like you were getting any help.
>
> tc
>
> -----Original Message-----
> From: Nguyen Ha Giang [mailto:giang@c...]
> Sent: Tuesday, March 05, 2002 2:40 AM
> To: ASP+
> Subject: [aspx] Please help me!
>
>
> Dear all,
> I'm learning program ASP.NET by C#. Pls teach me how draw 2D on web page,
> and manage mouse event on this page. I'm no have any material about
problem
> and I think MSDM of MS not enough technical material...
> Pls help me, thanks!
> Nguyen Ha Giang
>
>
Message #4 by "McCloy, Russell" <Russell.McCloy@B...> on Thu, 7 Mar 2002 09:27:20 +1100
|
|
Thanks Lewis,
I think this will do the trick.
Thanks for your help.
RuSS
-----Original Message-----
From: Lewis Bass [mailto:lewis@t...]
Sent: Thursday, 7 March 2002 1:36 AM
To: ASP+
Subject: [aspx] Re: OnSelectedIndexChanged question
I had a similiar problem - and i think that you are experieancing the same
thing.
When a aspx web page is posted back to the server the page init function
recreates the page. This would wipe out
any input that your user did. You need to change your page init function to
be similiar to the code below
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
<page initializition code here>
end if
end sub
I hope that this helps!
----- Original Message -----
From: "McCloy, Russell" <Russell.McCloy@B...>
To: "ASP+" <aspx@p...>
Sent: Tuesday, March 05, 2002 2:50 PM
Subject: [aspx] OnSelectedIndexChanged question
> Hi all,
>
> I have a question relating to the OnSelectedIndexChanged event of a
> dropdownlist.
> What I need to do is:
>
> when the OnSelectedIndexChanged event fires on my dropdownlist I want a
text
> box next to my dropdownlist to fill with the text
> of the selected item I chose in my drop down list.
>
> To begin with I set it up and the event wouldn't fire so I added the
> autopostback=true to my dropdownlist.
> This caused the event to fire but no matter what item I selected from my
> dropdownlist, only the top (index = 0) item
> would be placed in my text box.
>
> I suppose I could add some client side javascript to do this but I don't
> want to.
>
> How does one fire client side events?
>
> Thanks in advance,
>
> RuSs
>
> baker & McKenzie.
> Web Developer
>
> -----Original Message-----
> From: ToddC@m... [mailto:ToddC@m...]
> Sent: Wednesday, 6 March 2002 2:12 AM
> To: ASP+
> Subject: [aspx] RE: Please help me!
>
>
> I haven't done any graphics work (yet), but I think you need to look at
> GDI+. As for mouse events, this sounds like DHTML and is not really what
> .NET is about. JavaScript is still interpreted on the client, and any of
> the current JavaScripts books should be able to help you out with that.
>
> Sorry not much help, but it didn't sound like you were getting any help.
>
> tc
>
> -----Original Message-----
> From: Nguyen Ha Giang [mailto:giang@c...]
> Sent: Tuesday, March 05, 2002 2:40 AM
> To: ASP+
> Subject: [aspx] Please help me!
>
>
> Dear all,
> I'm learning program ASP.NET by C#. Pls teach me how draw 2D on web page,
> and manage mouse event on this page. I'm no have any material about
problem
> and I think MSDM of MS not enough technical material...
> Pls help me, thanks!
> Nguyen Ha Giang
>
>
Message #5 by "McCloy, Russell" <Russell.McCloy@B...> on Thu, 7 Mar 2002 19:17:33 +1100
|
|
Thanks for this, it worked great.
This message board really is great.
hope I can help someone in the future
thanks
RuSs
-----Original Message-----
From: Goh Mingkun [mailto:mangokun@h...]
Sent: Wednesday, 6 March 2002 12:56 PM
To: ASP+
Subject: [aspx] Re: OnSelectedIndexChanged question
Here is the steps I took to create a sample web application that test this
OnSelectedIndexChanged event:
Add a DropDownList control and a TextBox control onto the web form.
Set AutoPostBack = True for DropDownList1.
Go to View Code.
In the Page_Load event:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim i As Integer
For i = 1 To 12
DropDownList1.Items.Add(New ListItem(Format(New DateTime
(1800, i, 1), "MMM"), i))
Next
End If
End Sub
In the DropDownList1_SelectedIndexChanged event:
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
TextBox1.Text = DropDownList1.SelectedItem.Text
End Sub
That's all, and it works!
Message #6 by "Marcus Taylor" <mtaylor@i...> on Mon, 11 Mar 2002 12:19:03
|
|
The problem you might be having with the selected index being 0 could be
that when the postback is fired it relaods the page and fires the events
such as page_load. If you are building your drop down list in one of these
methods then it will probably be redrawn and therefore will have a
selected index of 0 before it processes any other code. If this is the
case add:
If Not IsPostBack Then
'your list bocx building code here
end if
Also ensure that enableviewstate is set to true in the dropdown properties,
Regards
Marcus
> Hi all,
>
> I have a question relating to the OnSelectedIndexChanged event of a
> dropdownlist.
> What I need to do is:
>
> when the OnSelectedIndexChanged event fires on my dropdownlist I want a
text
> box next to my dropdownlist to fill with the text
> of the selected item I chose in my drop down list.
>
> To begin with I set it up and the event wouldn't fire so I added the
> autopostback=true to my dropdownlist.
> This caused the event to fire but no matter what item I selected from my
> dropdownlist, only the top (index = 0) item
> would be placed in my text box.
>
> I suppose I could add some client side javascript to do this but I don't
> want to.
>
> How does one fire client side events?
>
> Thanks in advance,
>
> RuSs
>
> baker & McKenzie.
> Web Developer
>
> -----Original Message-----
> From: ToddC@m... [mailto:ToddC@m...]
> Sent: Wednesday, 6 March 2002 2:12 AM
> To: ASP+
> Subject: [aspx] RE: Please help me!
>
>
> I haven't done any graphics work (yet), but I think you need to look at
> GDI+. As for mouse events, this sounds like DHTML and is not really what
> .NET is about. JavaScript is still interpreted on the client, and any of
> the current JavaScripts books should be able to help you out with that.
>
> Sorry not much help, but it didn't sound like you were getting any help.
>
> tc
>
> -----Original Message-----
> From: Nguyen Ha Giang [mailto:giang@c...]
> Sent: Tuesday, March 05, 2002 2:40 AM
> To: ASP+
> Subject: [aspx] Please help me!
>
>
> Dear all,
> I'm learning program ASP.NET by C#. Pls teach me how draw 2D on web page,
> and manage mouse event on this page. I'm no have any material about
problem
> and I think MSDM of MS not enough technical material...
> Pls help me, thanks!
> Nguyen Ha Giang
>
Message #7 by "McCloy, Russell" <Russell.McCloy@B...> on Mon, 11 Mar 2002 23:19:12 +1100
|
|
Thanks Marcus,
I have actually solved this issue.
Your advice was the right advice though
thanks for your help..
RuSs
-----Original Message-----
From: Marcus Taylor [mailto:mtaylor@i...]
Sent: Monday, 11 March 2002 11:19 PM
To: ASP+
Subject: [aspx] Re: OnSelectedIndexChanged question
The problem you might be having with the selected index being 0 could be
that when the postback is fired it relaods the page and fires the events
such as page_load. If you are building your drop down list in one of these
methods then it will probably be redrawn and therefore will have a
selected index of 0 before it processes any other code. If this is the
case add:
If Not IsPostBack Then
'your list bocx building code here
end if
Also ensure that enableviewstate is set to true in the dropdown properties,
Regards
Marcus
> Hi all,
>
> I have a question relating to the OnSelectedIndexChanged event of a
> dropdownlist.
> What I need to do is:
>
> when the OnSelectedIndexChanged event fires on my dropdownlist I want a
text
> box next to my dropdownlist to fill with the text
> of the selected item I chose in my drop down list.
>
> To begin with I set it up and the event wouldn't fire so I added the
> autopostback=true to my dropdownlist.
> This caused the event to fire but no matter what item I selected from my
> dropdownlist, only the top (index = 0) item
> would be placed in my text box.
>
> I suppose I could add some client side javascript to do this but I don't
> want to.
>
> How does one fire client side events?
>
> Thanks in advance,
>
> RuSs
>
> baker & McKenzie.
> Web Developer
>
> -----Original Message-----
> From: ToddC@m... [mailto:ToddC@m...]
> Sent: Wednesday, 6 March 2002 2:12 AM
> To: ASP+
> Subject: [aspx] RE: Please help me!
>
>
> I haven't done any graphics work (yet), but I think you need to look at
> GDI+. As for mouse events, this sounds like DHTML and is not really what
> .NET is about. JavaScript is still interpreted on the client, and any of
> the current JavaScripts books should be able to help you out with that.
>
> Sorry not much help, but it didn't sound like you were getting any help.
>
> tc
>
> -----Original Message-----
> From: Nguyen Ha Giang [mailto:giang@c...]
> Sent: Tuesday, March 05, 2002 2:40 AM
> To: ASP+
> Subject: [aspx] Please help me!
>
>
> Dear all,
> I'm learning program ASP.NET by C#. Pls teach me how draw 2D on web page,
> and manage mouse event on this page. I'm no have any material about
problem
> and I think MSDM of MS not enough technical material...
> Pls help me, thanks!
> Nguyen Ha Giang
>
|
|
 |