Controls inside EditTemplate cause editing to end

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

I have a DataList control with an EditTemplate. Three of the controls in
this template include a Calendar, a Button with CommandName="update", and a
Button with CommandName="cancel". Whenever I click one of these controls,
the DataList replaces the EditTemplate with the ItemTemplate. I think this
is because the method I wrote which performs the databinding is getting
called, but I don't know why or where it is getting called from. It does not
get called from my Page_Load method and I do not have an ItemCommand event
handler, so I don't know where to start testing for it. I tested to see if
my UpdateCommand event is getting called when I click the Button with
CommandName="update" by assigning some text to a Label control, so I know
that it is never getting called. What could be causing my problem? Any help
would be appreciated. Thanks.
 
S

S. Justin Gengo

Nathan,

Make certain that your DataList control has it's viewstate property set to
true and then, wherever in your code you are binding the DataList, wrap that
code in:

If Not IsPostBack Then
'---Bind your DataList here.
End If

I don't know exactly where you are doing your databinding, but from what you
describe I think you have identified your problem correctly. Your DataList
is getting re-bound on postback.

By the way, please don't post to more than one newsgroup at a time...


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
B

Brock Allen

It's called from the Button's OnCommand event handler. The OnCommand is bubbled
up thru the part control hierarchy so child controls like the button can
send commands up to parent controls.
 
N

Nathan Sokalski

My DataList's EnableViewState property is set to True. I have tried wrapping
my binding code in an If Not IsPostBack Then statement like you said, but
that causes the binding to not occur at other times when it does need to
happen. I have a method that contains my binding code which I call in my
Page_Init method as well as after I make any changes to the database I use
as my datasource. This method is as follows:

Private Sub RefreshEvents()

Dim events As New DataSet

Dim myconnection As New
OracleConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionString"))

Dim cmdselect As New OracleCommand("SELECT * FROM eventlist WHERE
eventdate<TO_DATE('" & Date.Now.ToShortDateString() & "','MM/DD/YYYY')",
myconnection)

Dim cmddelete As New OracleCommand("", myconnection)

Dim eventsadapter As New OracleDataAdapter(cmdselect)

'Delete any past events and the people who registered for them

eventsadapter.Fill(events, "eventlist")

If events.Tables("eventlist").Rows.Count <> 0 Then

For Each pastevent As DataRow In events.Tables("eventlist").Rows

cmddelete.CommandText = "DELETE FROM registered WHERE eventid=" &
pastevent.Item("eventid")

myconnection.Open()

cmddelete.ExecuteNonQuery()

cmddelete.CommandText = "DELETE FROM eventlist WHERE eventid=" &
pastevent.Item("eventid")

cmddelete.ExecuteNonQuery()

myconnection.Close()

If pastevent.Item("details") <> "" AndAlso
System.IO.File.Exists(Server.MapPath("eventdetails/" &
pastevent.Item("details"))) Then
System.IO.File.Delete(Server.MapPath("eventdetails/" &
pastevent.Item("details")))

Next

End If

'Fill DataSet with all remaining events

events.Clear()

cmdselect.CommandText = "SELECT * FROM eventlist ORDER BY eventdate"

eventsadapter.SelectCommand = cmdselect

eventsadapter.Fill(events, "eventlist")

datEditEvents.DataSource = events

datEditEvents.DataBind()

ddlDeleteEvents.Items.Clear()

For Each existevent As DataRow In events.Tables("eventlist").Rows

ddlDeleteEvents.Items.Add(New
ListItem(CDate(existevent("eventdate")).ToShortDateString() & " " &
existevent("eventname"), existevent("eventid")))

Next

End Sub


Any other ideas? If you would like to see any of the other code I use, just
let me know. Thanks.
 
N

Nathan Sokalski

If that were true, why was my test code of assigning some text to a Label
not being called? Also, that still does not explain why the Calendar was
doing what it was doing. Thanks.
 
S

S. Justin Gengo

Leave the if then and then call the binding code when you need to from those
methods.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
N

Nathan Sokalski

I think you misunderstood what I meant. If I were to use the If Then like
you said, the If Then would have to go inside my RefreshEvents() method,
since that is the only place that I know is getting called during the
"undesired" databinding. However, if I did that, it would affect the
databinding when I don't want it to just like when I had the problem before.
If I knew where the "undesired" databinding was being called from (in other
words, what method calls RefreshEvents() when I don't want it to) I could
put the If Then there, but I don't know where that is. Another solution, if
it exists, would be to use an If Then with a condition based on what method
was calling it. Any ideas? Thanks.
 
S

S. Justin Gengo

Nathan,

You've got the solution at hand. You need to identify the undesired call(s)
to RefreshEvents() and put the If Then there.

That's really the only way to do it. If you're using Visual Studio now is
the time to set a breakpoint and see exactly what your code is doing...

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
N

Nathan Sokalski

I would like to set a breakpoint in Visual Studio to find the undesired
call, but unfortunately the site is on a remote server and according to the
person in charge of the server (who is also the person who taught me
ASP.NET) the server's ability to do debugging remotely has been turned off.
 
S

S. Justin Gengo

Hmmmm,

That's going to make it hard to identify...

What type of system are you on? I develop all my code on a Windows XP Pro
system running iis locally, then I deploy the code to a development server
for testing, Staging for more real-world testing, and finally production.

Can you set up your project to run locally and debug there?

Otherwise you're going to have to just really look at your code carefully...

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
N

Nathan Sokalski

I am running Windows XP Pro (and I do know how to use IIS on it), however, I
cannot set the project up on it for multiple reasons. First, the project
uses an Oracle DB which I do not have. Second, because it is a group project
as part of a temp job (it is not a personal site), it needs to be running on
the company's server and be available to my partner in the job (we are
students who got hired to continue a class project from the Spring 2005
semester). I have been looking really closely at my code, but because this
is my first time doing inline editing I am trying to get a little bit of
help from someone who has done it before.
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top