Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > How do you prevent postback data from being loaded into controls?

Reply
Thread Tools

How do you prevent postback data from being loaded into controls?

 
 
Monty
Guest
Posts: n/a
 
      07-20-2005

I've got a form that dynamically adds a DropDownList control to a page.
After the page is posted back the the code behind rebuilds the control
and resets the selected item. Problem is that the postback data
overrides what the code did. I would assume that no matter what it
would always be set to "Record Two" in the example below. Help?

Sample Code:

Public Class _Default
Inherits System.Web.UI.Page

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

Dim oDropDownList As New DropDownList
Dim oList As ListItem

With oDropDownList
.AutoPostBack = True
.ID = "test"
.EnableViewState = False

oList = New ListItem
oList.Value = "1"
oList.Text = "Record One"
.Items.Add(oList)

oList = New ListItem
oList.Value = "2"
oList.Text = "Record Two"
oList.Selected = True
.Items.Add(oList)

oList = New ListItem
oList.Value = "3"
oList.Text = "Record Three"
.Items.Add(oList)

oList = New ListItem
oList.Value = "4"
oList.Text = "Record Four"
.Items.Add(oList)

End With

phTest.Controls.Add(oDropDownList)

End Sub


End Class

 
Reply With Quote
 
 
 
 
Monty
Guest
Posts: n/a
 
      07-21-2005
Maybe I wasn't clear enough in my description. After the page loads
with the options, select "Record Four" on the page. After selecting,
the postback occurs and the controls are built again. One would think
that when the page rendered it would be reset back to "Number Two", but
it isn't.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
RE;Kontki if you delete kontiki any program you loaded with it in it 'will not work I have tried it with three programs and none work anymore (if you se it just stop download) 1-Twitch Computer Support 5 04-23-2009 02:45 PM
How does smartNavigation prevent Postback URL's from being added to the browser History? Itai ASP .Net Web Controls 0 08-10-2004 04:31 AM
How does smartNavigation prevent Postback URL's from being added to the browser History? Itai ASP .Net 0 08-10-2004 04:29 AM
How to prevent Postback URL's from being added to browser history =?Utf-8?B?Um9i?= ASP .Net 3 01-21-2004 07:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57