473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

User Control Post Back Issue

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.

Nov 19 '05 #1
7 2915
I guess you rebind your dropdown when postback , right? You will lose all the
info.
"di**********@gmail.com" wrote:
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.

Nov 19 '05 #2
IsPostBack() is your friend :}

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"di**********@gmail.com" wrote:
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.

Nov 19 '05 #3
> IsPostBack() is your friend :}

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

Rob.
Nov 19 '05 #4
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").Valu e = 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").V alue =
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

Nov 19 '05 #5
Try referencing:

ddOffice.SelectedItem.Value

--
-Demetri
"di**********@gmail.com" wrote:
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").Valu e = 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").V alue =
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

Nov 19 '05 #6
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.

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

Thanks.

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
11
by: Brian W | last post by:
Yet another editor problem To reproduce do the following 1) Open a Webform and switch to HTML edit mode 2) Enter the Following (include spaces) This is some text before <asp:hyperlink...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
0
by: Stephen robinson | last post by:
I wonder if anyone has come across this issue. I have a template ASPX page apon which I drop user controls which in effect are my web pages. This works fine and all the controls loop around and...
4
by: Alan Silver | last post by:
Hello, I have a repeater showing a list of items and I would like to be able to allow the user to change the order of the items. I have absolutely no idea how to go about this, other than having...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
3
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive...
9
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in...
1
by: Dave A | last post by:
I have a problem that I have boiled down to a very simple example. I have a user control that displays a some data from a business object. On one screen I have a collection of these business...
11
by: Brad Baker | last post by:
I'm building a small web application - I started out placing all my code in one file (config.aspx). As I continue to add code though it was becoming very unwieldy. After doing some searching...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.