Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Nathan Sokalski #1
Determining What Control Caused The PostBack
I have a DataList that I was having trouble getting the events for. After a
bit of help, I realized that I needed to put the databinding inside an If
Not IsPostBack() condition. Although this fixed the individual problem, it
caused problems in other areas. This is because the DataSource that I use
for my databinding changes and must be "rebound". Because there is only one
situation where I need the If Not IsPostBack() condition, I think it would
be easiest if I could somehow determine what control caused the
IsPostBack(). Is there any way to do this? Thanks.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
Nathan Sokalski Guest
-
Determining row that caused an ItemCommand
I have an Edit button on a datagrid. When the edit button is clicked, how do i know which row is the one where the button was clicked? -
Did my control caused the postback
You want to know it on Page or in the control itself? If your control implements IPostBackEventHandler, you could override RaisePostBackEvent on... -
What Control Caused the PostBack?
Is there any way to dynamically get the name of the control that caused the postback? Since SmartNav is not working for me I'm trying to implement a... -
How to determine Control that caused Postback?
My event target is blank. Why would it be blank? I put a value in for the CommandArgument and CommandName. I am using the following syntax...... -
How to see what caused PostBack
I have few buttons on a page. In Page_Load I would like to determine which one caused post back. How to do? -
Mark Rae #2
Re: Determining What Control Caused The PostBack
"Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
news:eEJFDqdsFHA.2880@TK2MSFTNGP12.phx.gbl...
The easiest way by far is to take your databinding code out of your> Is there any way to do this?
Page_Load and put it in a separate private method which you then call every
time you need to bind the data.
Mark Rae Guest
-
Nathan Sokalski #3
Re: Determining What Control Caused The PostBack
Although I was already doing that, I think you may have solved my problem.
Rather than calling the method from Page_Init where I should have, I was
calling it from Page_Load. But now that I moved it to Page_Init, everything
seems to be good. Thanks.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
"Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:u1QtJvdsFHA.2948@TK2MSFTNGP15.phx.gbl...> "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
> news:eEJFDqdsFHA.2880@TK2MSFTNGP12.phx.gbl...
>>>> Is there any way to do this?
> The easiest way by far is to take your databinding code out of your
> Page_Load and put it in a separate private method which you then call
> every time you need to bind the data.
>
Nathan Sokalski Guest
-
Cor Ligthert [MVP] #4
Re: Determining What Control Caused The PostBack
Nathan,
Can you tell us why the above is, because in my idea it is better to solve> Although this fixed the individual problem, it caused problems in other
> areas. This is because the DataSource that I use for my databinding
> changes and must be "rebound".
the problem than to create spaghetti around simple methods that you did not
implement in your program?
Cor
Cor Ligthert [MVP] Guest
-
Nathan Sokalski #5
Re: Determining What Control Caused The PostBack
It is probably partially due to the fact that this is the first time I am
using the inline editing technique of DataLists/DataGrids, but I think the
reason is also because my page has three sections on it:
1. Creating a new record in the database (this uses a simple textbox &
button form)
2. Editing an existing record (this is the one that is new to me)
3. Delete an existing record (this is a dropdownlist & button)
If I had done inline editing before, I probably would have combined the
three parts into one DataList that included a Delete button as well as an
Edit button, and had a button somewhere to create a blank record that could
be edited. I did not do this this time because I was learning inline editing
for the first time, self-taught, and I had to have the form finished for a
temporary job, so I wanted to make sure the minimum of being able to add and
delete worked, so I will admit that it's not the most efficient code right
now. But now that I know the basics, I will probably be more efficient in
the future.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:OqH2Y6dsFHA.1172@TK2MSFTNGP11.phx.gbl...> Nathan,
>>>> Although this fixed the individual problem, it caused problems in other
>> areas. This is because the DataSource that I use for my databinding
>> changes and must be "rebound".
> Can you tell us why the above is, because in my idea it is better to solve
> the problem than to create spaghetti around simple methods that you did
> not implement in your program?
>
> Cor
>
Nathan Sokalski Guest
-
Nathan Sokalski #6
Re: Determining What Control Caused The PostBack
I am now having a related problem. I have my Edit button (the button from
the ItemTemplate) working, but three of the controls in the EditTemplate (a
Calendar control, a Button with CommandName="update", and a Button with
CommandName="cancel"). Whenever I click on any of these controls the
EditItem returns to being just an Item. I am assuming this is because the
method I made to do the binding is somehow getting called. However, I can't
figure out where it is getting called from, since my Page_Load does not
include it (my Page_Load simply assigns a value to a Label's Text property).
Any ideas? Here is my databinding code and my DataList events:
Private Sub RefreshEvents()
Dim events As New DataSet
Dim myconnection As New
OracleConnection(System.Configuration.Configuratio nSettings.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")).ToShortDat eString() & " " &
existevent("eventname"), existevent("eventid")))
Next
End Sub
Private Sub datEditEvents_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datEditEvents.EditCommand
datEditEvents.EditItemIndex = e.Item.ItemIndex
Me.RefreshEvents()
End Sub
Private Sub datEditEvents_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datEditEvents.UpdateCommand
If CType(e.Item.FindControl("calEditDate"), Calendar).SelectedDate >
Date.Today() Then
CType(e.Item.FindControl("lblDateError"), Label).Visible = False
If CType(e.Item.FindControl("txtEditName"), TextBox).Text <> "" Then
CType(e.Item.FindControl("lblNameError"), Label).Visible = False
CType(e.Item.FindControl("revEditDesc"),
RegularExpressionValidator).Validate()
If CType(e.Item.FindControl("revEditDesc"),
RegularExpressionValidator).IsValid Then
Dim myconnection As New
OracleConnection(System.Configuration.Configuratio nSettings.AppSettings("connectionString"))
Dim cmdupdate As New OracleCommand("UPDATE eventlist SET eventname='" &
CType(e.Item.FindControl("txtEditName"), TextBox).Text.Replace("'", "''") &
"',description='" & CType(e.Item.FindControl("txtEditDesc"),
TextBox).Text.Replace("'", "''") & "',eventdate=TO_DATE('" &
CType(e.Item.FindControl("calEditDate"),
Calendar).SelectedDate.ToShortDateString() & "','MM/DD/YYYY')",
myconnection)
If CType(e.Item.FindControl("radNoDetails"), RadioButton).Checked Then
'Delete existing file
If e.CommandArgument <> "" AndAlso
System.IO.File.Exists(Server.MapPath("eventdetails/" & e.CommandArgument))
Then System.IO.File.Delete(Server.MapPath("eventdetails/" &
e.CommandArgument))
'Set details=''
cmdupdate.CommandText &= ",details=''"
End If
If CType(e.Item.FindControl("radNewDetails"), RadioButton).Checked Then
'Delete existing file
If e.CommandArgument <> "" AndAlso
System.IO.File.Exists(Server.MapPath("eventdetails/" & e.CommandArgument))
Then System.IO.File.Delete(Server.MapPath("eventdetails/" &
e.CommandArgument))
'Upload new file
Dim upfilename As String = ""
If fileDetails.Value <> "" AndAlso fileDetails.PostedFile.ContentLength > 0
Then
Dim dir As String() =
fileDetails.PostedFile.FileName.Split("\".ToCharAr ray())
upfilename = dir(dir.GetUpperBound(0))
fileDetails.PostedFile.SaveAs(Server.MapPath("even tdetails/" & upfilename))
End If
'Set details to new filename
cmdupdate.CommandText &= ",details='" & upfilename & "'"
End If
cmdupdate.CommandText &= " WHERE eventid=" &
datEditEvents.DataKeys(e.Item.ItemIndex)
myconnection.Open()
cmdupdate.ExecuteNonQuery()
myconnection.Close()
datEditEvents.EditItemIndex = -1
Me.RefreshEvents()
End If
Else
CType(e.Item.FindControl("lblNameError"), Label).Visible = True
End If
Else
CType(e.Item.FindControl("lblDateError"), Label).Visible = True
End If
End Sub
Private Sub datEditEvents_CancelCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
datEditEvents.CancelCommand
datEditEvents.EditItemIndex = -1
Me.RefreshEvents()
End Sub
Thank you so much.
--
Nathan Sokalski
[email]njsokalski@hotmail.com[/email]
[url]http://www.nathansokalski.com/[/url]
"Mark Rae" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:u1QtJvdsFHA.2948@TK2MSFTNGP15.phx.gbl...> "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
> news:eEJFDqdsFHA.2880@TK2MSFTNGP12.phx.gbl...
>>>> Is there any way to do this?
> The easiest way by far is to take your databinding code out of your
> Page_Load and put it in a separate private method which you then call
> every time you need to bind the data.
>
Nathan Sokalski Guest



Reply With Quote

