Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Control Events Not Firing

Status
Not open for further replies.

Modica82

Technical User
Jan 31, 2003
410
GB
Hi all,

Yes i am the one with all the States problems and i still have not managed to get rid of them!!

Can someone just explain something to me as i dont understand what is happening, i have a user control, which just for peace of mind i have set at runtime, i mean i have set the tag prefix etc and physically placed it on the page, still i have my viewState problems which i really do not understand!! but what my main problem is my events are not firing up???

on this user control i have two dropdown lists the first one has an onSelectedItemChanged event which fires up, and populates the second combo, i have this working now, but i still require a round trip to the server(as my state is not maintained) which is something i will have to address. But i also have a onSelectedItemChanged event in my second drop down, which doesnt work, and i dont know why it doesnt work!?? i did also populate the second drop down on page_init event(within my user control) and then the event fires up, but that is wrong as that means i cant dynamically populate the dropdownlist!???

Can anyone help me, i have had the worst couple of days for a long time!!

Rob
 
Since it is very easy to change an .aspx into an .ascx I would make sure it worked correctly as an aspx. Then at the very least you know it is a state problem caused by being a uc. Not a solution but a course of action that could eliminate possible problems making your pool smaller.
Marty
 
Works fine as an ASPX page, when i pull it in it breaks, it must be a problem with user controls, which really if it is the case, makes a mockery of the whole ASP.Net architecture, ok maybe a bit over the top there, but i am very annoyed about this! Any suggestions i am sure i wont say no to them!

Rob
 
Can anyone see anything wrong with this code, as i cannot:

<%@ Import Namespace=&quot;Country.Business&quot; %>
<%@ Import Namespace=&quot;Resort.Business&quot; %>

<script runat=&quot;server&quot;>


sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)

If Page.IsPostBack = False Then
BindData()
End If

End Sub

sub BindData()

'Create Instance To DataObjects
Dim countries As New CountryBiz()

'Set Properties For Country DropDown List
Country.DataSource = countries.GetCountries()
Country.DataValueField = &quot;ID&quot;
Country.DataTextField = &quot;CountryName&quot;
Country.DataBind()

'Add Default DataList Item
Country.Items.Insert(0, &quot;Select A Country&quot;)

End Sub

Sub CountryChanged(ByVal Sender As Object, ByVal e As EventArgs)

'Create Instance Of Resorts DataObject
Dim resorts As New ResortsBiz()
Dim CountryID As Integer = Country.SelectedItem.Value

'Set Properties For Resort DropDown List
Resort.DataSource = resorts.getResortsByCountry(CountryID)
Resort.DataValueField = &quot;ID&quot;
Resort.DataTextField = &quot;ResortName&quot;
Resort.DataBind()

'Enable Resort Drop Down List
Resort.Enabled = True

'Add Default DataList Item
Resort.Items.Insert(0, &quot;Select A Resort&quot;)

End Sub

sub ResortChanged(byVal Sender As Object, ByVal e As EventArgs)

Dim ResortID As Integer = Resort.SelectedItem.Value

If ResortID <> 0 Then
Response.redirect(&quot;./Resorts/resortDetails.aspx?ID=&quot; & ResortID & &quot;&Parent=0&Section=2&quot;)
End If

End Sub
</script>

<asp:dropdownlist ID=&quot;Country&quot;
runat=&quot;server&quot;
autopostback=&quot;true&quot;
onSelectedIndexChanged=&quot;CountryChanged&quot;
EnableViewState=&quot;True&quot;
cssClass=&quot;clInput&quot;
width=&quot;160&quot;
/>

<asp:dropdownlist ID=&quot;Resort&quot;
runat=&quot;server&quot;
autopostback=&quot;true&quot;
onSelectedIndexChanged=&quot;ResortChanged&quot;
EnableViewState=&quot;True&quot;
cssClass=&quot;clInput&quot;
width=&quot;160&quot;
enabled=&quot;false&quot;
/>
 
What does the InitializeComponent look like? I use C# so I hope the terminology is the same. Does vb implicitly cast a string to an int?
Marty
 
I must apologise to Microsoft, i have been sitting here for a full day getting more and more fustrated at why none of my controls worked and the whole reason was the fact that when i first started using .Net i decided to set the forms enableViewState property to false, i must have been half asleep and i know am sitting here looking the fool!

Thank you everyone for your responces

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top