473,324 Members | 2,239 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,324 software developers and data experts.

Losing ddl and repeater items on postback

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
Nov 19 '05 #1
1 2694
I just realised that I had set the AutoPostBack property to true in
design view for the ddl. One problem solved.

Nov 19 '05 #2

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

Similar topics

3
by: anon | last post by:
I am having a hard time with makeing what I am trying to do work. I am making a questionaire web app. I have a custom control that has a label and 5 radio buttons. My problem is that each...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
3
by: Kevin Cunningham | last post by:
I have a repeater with some labels in it (code below). For whatever reason the text for the label is not persisted in viewstate on the postback. Is there a trick to get this to work? Is there...
4
by: Dave | last post by:
Well... with data in the textbox.. This did not work... <asp:TableCell ID="Tablecell1" CssClass="lnk_results" Runat="server" Width="35%" HorizontalAlign="Left" ColumnSpan="5"> <asp:TextBox...
1
by: Andy | last post by:
team, my postback is changing once i bind an arraylist to a repeater. how can i get the postback to return true? ''''''''''''''''''''''''''''''''''''''''' 'declarations
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
2
by: Nemo | last post by:
Hi, I have i fishy problem when I have e Repeater with user controls. page_load { if (!isPostBack) { repeater.databind(); }
1
by: Jeremy | last post by:
Hello All, I have a Repeater which contains a Dynamic DropDownList within its itemtemplate. I know I have struggled with this before and I am pretty sure I had to save a bunch of crap manually...
1
by: supraracer | last post by:
Can anyone show me an example of a solution to the problem described in this thread? How do I rebind a label in a repeater on a postback? ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.