Losing ddl and repeater items on postback

  • Thread starter Matthew Curiale
  • Start date
M

Matthew Curiale

I have a ddl that is populated in my If Not IsPostBack block in the
Page_load event. A repeater is also populated at this time, showing
different domains for a website. The ddl contains different price
plans that can be selected.

My problem is that the user has a choice of being able to update
information, or update and create a new domain. In doing either, if
the user changes the index of the ddl, I lose all data in the ddl, and
my repeater disappears, also. I cannot understand why it is happening.

I have tried having my binddatagrid() function call in the Not
IsPostBack block alone, I have tried coupling it with another call in
the ddl_SelectedIndexChanged event, and also with it in the update
call. I will post my code below.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'pull the domain id from session, and query the domain db, and
bind the dropdown list
'also stores the name of the client from session, in a textbox
If Not IsPostBack Then
domainID = Session("domainID")
websiteID = Session("websiteID")
Website.Value = websiteID
binddropdownlist()
doPaging(websiteID)
PopulateTextBoxes(websiteID)
btnUpdate.Attributes.Add("onClick",
"javascript:return(confirmation());")
Else
Session.Add("domainID", domainID)
Session.Add("websiteID", websiteID)
End If
lblClientName.Text = Session("client_name")
Session("website_id") = Request("website")
End Sub

Private Sub binddropdownlist()
Dim cmdDDL As New SqlCommand("stp_registrar_plan_dropdown",
connection)
Dim dsDDL As New DataSet
connection.Open()
cmdDDL.CommandType = CommandType.StoredProcedure
Dim daDDL As New SqlDataAdapter(cmdDDL)
daDDL.Fill(dsDDL, "stp_registrar_plan_dropdown")
ddlPlan.DataSource = dsDDL
ddlPlan.DataMember = "stp_registrar_plan_dropdown"
ddlPlan.DataTextField = "plan_description"
ddlPlan.DataValueField = "plan_id"
ddlPlan.DataBind()
connection.Close()
End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
Dim websiteID As String = Request("website")
Dim cmdUpdateNameAndComments As New SqlCommand("update
t_website_id set name = '" & txtWebsiteName.Text & "', comments = '" &
txtWebsiteComments.Text & "' " _
& "where
website_id = '" & websiteID & "'", connection)
connection.Open()
cmdUpdateNameAndComments.ExecuteNonQuery()
connection.Close()
doPaging(websiteID)
PopulateTextBoxes(websiteID)
Dim tempWebID As String
Dim tempID As String = Session("tempID")
Dim cmdFind As New SqlCommand("Select * from t_website_id
where id = '" & tempID & "'", connection)
Dim dsFind As New DataSet
Dim yesNo As Integer = Request("newDomain")
connection.Open()
Dim daFind As New SqlDataAdapter(cmdFind)
daFind.MissingSchemaAction = MissingSchemaAction.AddWithKey
daFind.Fill(dsFind, "t_website_id")
Dim dr As DataRow
For Each dr In dsFind.Tables("t_website_id").Rows
If dr("website_id") = websiteID Then
tempWebID = dr("website_id")
End If
Next
Dim cmdInsertPlan As New SqlCommand("insert into
t_website_hosting_plan(website_id, plan_id, auto_renew) values('" &
websiteID & "', '" & ddlPlan.SelectedItem.Value & "', '1')",
connection)
cmdInsertPlan.ExecuteNonQuery()
'This is from a js function that checks to see if they want to create
'a new domain also, or just update the information
If yesNo = 0 Then
Dim domain As String = "update t_domain_id set domain =
'', registrar = '', create_date = '" & Now.Date & "', website_id = '"
& tempWebID & "' " _
& "WHERE website_id = '" & tempWebID
& "'"
Dim cmdAddDomain As New SqlCommand(domain, connection)
cmdAddDomain.ExecuteNonQuery()
Dim dsDomain As New DataSet
Dim cmdDomain As New SqlCommand("Select * from t_domain_id
where website_id = '" & tempWebID & "'", connection)
cmdDomain.CommandType = CommandType.Text
Dim daDomain As New SqlDataAdapter(cmdDomain)
daDomain.Fill(dsDomain, "t_domain_id")
Dim tempDomainID As String
For Each dr In dsDomain.Tables("t_domain_id").Rows
tempDomainID = dr("domain_id")
Next
Session.Add("websiteID", tempWebID)
Session.Add("domainID", tempDomainID)
Server.Transfer("client_domain_modify.aspx", True)
Else
Dim update As String = "update t_website_id set name = '"
& txtWebsiteName.Text & "', comments = '" & txtWebsiteComments.Text &
"' " _
& "where website_id = '" & tempWebID &
"'"
Dim cmdUpdate As New SqlCommand(update, connection)
cmdUpdate.ExecuteNonQuery()
Session.Add("websiteID", tempWebID)
Server.Transfer("client_website_list.aspx")
End If
connection.Close()
End Sub

Like I said above, I have tried a few different things with my binding
call, and either I get no data and no repeater when the
selectedindexchanged even fires, or I get the Object Reference not set
to an instance of an object error.

Any help would be appreciated!

TIA,

Matthew
 
M

mattcur

I just realised that I had set the AutoPostBack property to true in
design view for the ddl. One problem solved.
 

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

Top