User Control Post Back Issue

D

dickson.matt

Ok simple question (that I feel dumb for asking)....

I have created a user control (ascx page) that contains a dropdown
list.

The problem I am having is that when the postback occurs I can only
read the selected value from the dropdown list that was originally
selected. I can't read the current selected value of the control...

For example, the dropdown has values for Apples and Oranges. When the
page first populates Apples is selected. THe value is then changed to
Oranges on the form. When the postback occurs I check the selected
value of the usercontrol (I have exposed a property that returns the
SelectedValue of the dropdown) it shows Apples even though Oranges was
selected.

I know this is b/c I need to get the value from the Request.Form.Item
but if I read the value of Request.Form.Item ("mycontrol"), I get
nothing.
 
R

Rob Nicholson

IsPostBack() is your friend :}

But like most friends, you can fall out sometimes :)

Rob.
 
D

dickson.matt

No, actually I don't.

Here are some code snippets.....
From the page_load of the page containing my user control

If Not Page.IsPostBack Then
'Retrieve page data
daData.SelectCommand.Connection = connSQL
daData.SelectCommand.Parameters("@intUserId").Value = 1

daData.Fill(DsUser1, "spDpUser")

Page.DataBind()
End If
From the btnSave_Click event of the page containing my control

'Setup connection for update command
daData.UpdateCommand.Connection = connSQL

'Set paramaters for SQL call

'Textbox driven paramaters
daData.UpdateCommand.Parameters("@u_first_name").Value =
Request.Form.Item("txtFirstName").ToString()

'Dropdown driven paramaters (user controls)
daData.UpdateCommand.Parameters("@u_primax_office").Value =
Office1.SelectedValue

This is where I am getting a value of 1 even though 2 is what is
currently selected. I tried using Request.From.Item("Office1") but
that doesn't work. Which makes sense b/c I really want the value of
ddOffice which is in Office1.

This is the code for my office user control (ascx)

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
daData.Fill(DsOffice, "spDpCodesOffice")
ddOffice.DataSource = DsOffice

ddOffice.DataBind()
End If

End Sub

Public Property SelectedValue()
Get
Return ddOffice.SelectedValue
End Get
Set(ByVal Value)
ddOffice.SelectedValue = Value
End Set
End Property
 
T

tricky one

That doesn't work. ddoffice is contained in office1 which is a ascx
user control.

That I know of there is no way to say
office1.ddoffice.selecteditem.value either.
 
T

tricky one

Anyone else have any idea how to accomplish this. I am stuck and can't
continue until I get an answer.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top