Customer DropDownList and ViewState

Results 1 to 2 of 2

Thread: Customer DropDownList and ViewState

  1. #1
    Join Date
    Dec 1969

    Default Customer DropDownList and ViewState

    Hi, I have created a Custom DDL, my problem is how do I create view state to maintain the value in the Custom Control, right now it always go back to &#060;Select&#062; after I post the page.<BR><BR>Public Class CustomerDropDownList<BR> Inherits System.Web.UI.WebControls.DropDownList<BR><BR> Protected Overrides Sub OnPreRender(ByVal e As EventArgs)<BR> <BR> Dim myDataTable as DataTable<BR><BR> &#039;Database returns a recordset to myDataTable <BR> <BR> me.DataSource = myDataTable<BR> me.DataTextField = "CustomerName"<BR> me.DataValueField = "CustomerID"<BR> me.DataBind()<BR> me.Items.Insert(0, New ListItem("&#060; Select &#062;", ""))<BR> <BR> MyBase.OnPreRender(e)<BR> End Sub<BR>End Class

  2. #2
    Join Date
    Dec 1969

    Default RE: Customer DropDownList and ViewState

    So you have over-ridden the OnPreRender, which fires every time the page is loaded including postbacks. In this override you bind the DDL. What would you think would happen? If you are new and honestly don&#039;t know, go read up on IsNotPostBack.<BR><BR>Personally, I think having the DataBind in the PreRender is not the best design, but I suppose that you could wrap the DB query and binding code is an &#039;if (IsNotPostback())&#039;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts