Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old May 3rd, 2011, 09:24 AM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Javascript functions from Gridview RowCommand Event

Hi Imar

I've tried the suggestion of RegisterStartupScript

[CODE] If (e.CommandName = "Cancel") Then

' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)

' Retrieve the row that contains the button from the Rows collection.
Dim row As GridViewRow = GridViewReservations.Rows(index)
PublicationID = row.Cells(0).Text

' Retrieve the row that contains the button from the Rows collection.
Dim rowTwo As GridViewRow = GridViewReservations.Rows(index)
Status = rowTwo.Cells(2).Text

If Status = "Out on Loan\Reserved for Loan" Then

Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
Dim reservationStatus = (From publication In myLiteratureCatalogue.Publications Where publication.PublicationID = (PublicationID) Select publication).First()

' Change the status of the publication.
reservationStatus.ReservationID = Nothing
reservationStatus.StatusID = (2)

myLiteratureCatalogue.SaveChanges()

End Using

'System.Threading.Thread.Sleep(5000)
Call ReservationCancellationNotification()[/CODE]

Code:
Protected Sub ReservationCancellationNotification()

        ' Define the name and type of the client scripts on the page. 
        Dim csname1 As [String] = "PopupScript"
        Dim cstype As Type = Me.[GetType]()

        ' Get a ClientScriptManager reference from the Page class. 
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Check to see if the startup script is already registered. 
        If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
            Dim cstext1 As New StringBuilder()
            cstext1.Append("<script type=text/javascript> alert('This reservation has now been cancelled') </")
            cstext1.Append("script>")

            cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
        End If

    End Sub
This does exactly as it says on the tin so to speak but for some reason my call for the 'ReservationCancellationNotification sub' never goes through. I know the procedure you suggested works because I've also tried calling it at the page load event which goes through as intended.

When I hit the 'Cancel' button field in my gridview, the gridview never refreshs to show the updated gridview, i.e. without the cancelled record. This was the reason I included the response.redirect to refresh the gridview?

Do you have any suggestions Imar?
Reply With Quote
  #12 (permalink)  
Old May 3rd, 2011, 11:47 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Are you sure your command handler gets called? E.g. when you debug the code, do you see it hit your sub?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #13 (permalink)  
Old May 3rd, 2011, 12:43 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Debug Error

Hi Imar

I get the following error when I debug the affected page. Does this mean it can't find the JScript plug-in?

Quote:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorExceptio n: The GridView 'GridViewReservations' fired event RowCancelingEdit which wasn't handled.
HTML Code:
<%@ Page Title="Shap Library Resources - User Account Information " Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="MyAccountDefault.aspx.vb" Inherits="UsersPages_UserDefault" %>


<asp:Content ID="Content1" ContentPlaceHolderID="cpMainContent" Runat="Server">

<script type="text/javascript">

    function ReservationCancelled() {
        alert("This reservation has now been cancelled");
    }

 </script>

 <script type="text/javascript">

     function LoanAvailable() {
         alert("You may now collect the publication from the Central Business Unit team");
     }

 </script>

 <script type="text/javascript">

     function LoanNotAvailable() {
         alert("This publication is not currently available for loan");
     }

 </script>

    <div class="Position">

    <asp:UpdatePanel ID="UpdatePanel" runat="server">
        <ContentTemplate>
            <table style="width: 100%">
                <tr>
                    <td style="text-align: center">
                        <asp:LoginName ID="LoginName" runat="server" FormatString="Welcome back {0}" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <strong>Office Base</strong></td>
                </tr>
                <tr>
                    <td>
                        <asp:DetailsView ID="UserDetailsView" runat="server" CellPadding="4" 
                            FieldHeaderStyle-Width="250px" ForeColor="#333333" GridLines="None" 
                            Height="50px" Width="752px" AutoGenerateRows="False">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                            <EditRowStyle BackColor="#999999" />
                            <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
                            <Fields>
                                <asp:BoundField DataField="ServiceDescription" HeaderText="Service Description" 
                                    SortExpression="ServiceDescription" />
                                <asp:BoundField DataField="AddressLine1" HeaderText="Address Line 1" 
                                    SortExpression="AddressLine1" />
                                <asp:BoundField DataField="AddressLine2" HeaderText="Address Line 2" 
                                    SortExpression="AddressLine2" />
                                <asp:BoundField DataField="TownDescription" HeaderText="Town " 
                                    SortExpression="TownDescription" />
                                <asp:BoundField DataField="AddressPostcode" HeaderText="Postcode" 
                                    SortExpression="AddressPostcode" />
                                <asp:BoundField DataField="TelephoneNumber" 
                                    HeaderText="Service Telephone Number" SortExpression="TelephoneNumber" />
                            </Fields>
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        </asp:DetailsView>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="LabelNullReservations" runat="server" CssClass="Response" Text="You currently have no publication reservations!" Visible="False" />
                        <asp:GridView ID="GridViewReservations" runat="server" AllowPaging="True" 
                            AutoGenerateColumns="False" CellPadding="4" 
                            Font-Names="tahoma" ForeColor="#333333" GridLines="None" Width="751px" 
                            HorizontalAlign="Right">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:BoundField DataField="PublicationID" ItemStyle-Width="60px" HeaderText="ID" InsertVisible="False" SortExpression="PublicationID" >
                                <ItemStyle Width="60px" />
                                </asp:BoundField>
                                <asp:BoundField DataField="Title" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="300px" HeaderText="Publication Title" SortExpression="Title" >
                                
                                <ItemStyle HorizontalAlign="Center" />
                                </asp:BoundField>
                                
                                <asp:BoundField DataField="StatusDescription" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" HeaderText="Status" 
                                    SortExpression="StatusDescription" >
                                
                                <ItemStyle HorizontalAlign="Center" />
                                </asp:BoundField>
                                
                                <asp:ButtonField ButtonType="Button" ItemStyle-HorizontalAlign="Right" ControlStyle-Width="80px" ControlStyle-CssClass="Button" CommandName="Loan" Text="Loan" />
                               
                               <asp:ButtonField ButtonType="Button" ItemStyle-HorizontalAlign="Right" ControlStyle-Width="80px" ControlStyle-CssClass="Button" CommandName="Cancel" Text="Cancel" />

                                </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="LabelNullLoans" runat="server" CssClass="Response" Text="You currently have no publication loans!" Visible="False" />
                        <asp:GridView ID="GridViewLoans" runat="server" AllowPaging="True" 
                            AutoGenerateColumns="False" CellPadding="4" Font-Names="tahoma" 
                            ForeColor="#333333" GridLines="None" Width="751px">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:BoundField DataField="Title" HeaderText="Publication Title" />
                                <asp:BoundField DataField="EndLoanDate" DataFormatString="{0:dd/MM/yyyy}" 
                                    ItemStyle-Width="150px" HeaderText="Return Due Date" 
                                    ItemStyle-HorizontalAlign="Center"  >
                                <ItemStyle HorizontalAlign="Center" Width="150px" />
                                </asp:BoundField>
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#E9E7E2" />
                            <SortedAscendingHeaderStyle BackColor="#506C8C" />
                            <SortedDescendingCellStyle BackColor="#FFFDF8" />
                            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="ChangeAccountPasswordButton" runat="server" CssClass="Button" 
                            PostBackUrl="~/UsersPages/ChangePassword.aspx" Text="Change Account Password" 
                            Width="200px" />
                    </td>
                </tr>
            </table>

        </ContentTemplate>
    </asp:UpdatePanel>

</div>
</asp:Content>
Code:
Imports Model1.Literature_Cataloguing_SystemEntities
Imports System.IO
Imports System.Net.Mail
Imports System.Data.SqlClient

Partial Class UsersPages_UserDefault
    Inherits System.Web.UI.Page

    Dim currentUser As String = Membership.GetUser().UserName
    Dim PublicationID As Integer
    Dim PubTitle As Integer
    Dim Status As String
    Dim ExistingUser As MembershipUser = Membership.GetUser(currentUser)
    Dim UserId As Guid = CType(ExistingUser.ProviderUserKey, Guid)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Call GetOfficeDetails()
        Call GetReservationDetails()
        Call GetLoanDetails()

        If GridViewReservations.Rows.Count = 0 Then
            LabelNullReservations.Visible = True
        End If

        If GridViewLoans.Rows.Count = 0 Then
            LabelNullLoans.Visible = True
        End If

    End Sub

    Protected Sub GetOfficeDetails()

        Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
            Dim allOfficeDetails = From aspnet_Users In myLiteratureCatalogue.aspnet_Users
                                   From service In myLiteratureCatalogue.Services
                                   From town In myLiteratureCatalogue.Towns()
                                   Where aspnet_Users.ServiceID = service.ServiceID
                                   Where service.TownID = town.TownID
                                   Where aspnet_Users.UserId = (UserId)
                                  Select service.ServiceDescription, service.AddressLine1, service.AddressLine2, town.TownDescription, service.AddressPostcode, service.TelephoneNumber
            UserDetailsView.DataSource = allOfficeDetails
            UserDetailsView.DataBind()

        End Using

    End Sub

    Protected Sub GetReservationDetails()

        Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
            Dim allReservationsDetails = From publication In myLiteratureCatalogue.Publications
                                 From status In myLiteratureCatalogue.Status
                                 From loan In myLiteratureCatalogue.Loans
                                 Where publication.StatusID = status.StatusID
                                 Where publication.StatusID = (3) Or (4)
                                 Where publication.ReservationID = (UserId)
                                 Select publication.PublicationID, publication.Title, status.StatusDescription
            GridViewReservations.DataSource = allReservationsDetails
            GridViewReservations.DataBind()

        End Using

    End Sub

    Protected Sub GetLoanDetails()

        Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
            Dim allLoanDetails = From loan In myLiteratureCatalogue.Loans
                                 From publication In myLiteratureCatalogue.Publications
                                 From status In myLiteratureCatalogue.Status
                                 Where loan.PublicationID = publication.PublicationID
                                 Where publication.StatusID = status.StatusID
                                 Where status.StatusID = (2) Or (4)
                                 Where loan.UserId = (UserId)
                                 Select publication.Title, loan.EndLoanDate
            GridViewLoans.DataSource = allLoanDetails
            GridViewLoans.DataBind()

        End Using

    End Sub

    Protected Sub UserConfirmation()

        Dim User As String = Membership.GetUser().UserName
        Dim Email As String = Membership.GetUser().Email

        Dim fileName As String = Server.MapPath("~/App_Data/LoanVerification.txt")
        Dim mailBody As String = File.ReadAllText(fileName)

        mailBody = mailBody.Replace("<%UserName%>", User)
        mailBody = mailBody.Replace("<%PublicationTitle%>", PubTitle)

        Dim myMessage As MailMessage = New MailMessage()
        myMessage.Subject = "User Resource Loan Request"

        myMessage.Body = mailBody

        myMessage.To.Add(New MailAddress(Email))

        Dim mysmtpClient As SmtpClient = New SmtpClient()
        mysmtpClient.Send(myMessage)

    End Sub

    Protected Sub CBULoanConfirmation()

        Dim User As String = Membership.GetUser().UserName

        Dim fileName As String = Server.MapPath("~/App_Data/CBUTeamLoanVerification.txt")
        Dim mailBody As String = File.ReadAllText(fileName)

        mailBody = mailBody.Replace("<%UserName%>", User)
        mailBody = mailBody.Replace("<%PublicationTitle%>", PubTitle)

        Dim myMessage As MailMessage = New MailMessage()
        myMessage.Subject = "Loan request from library resource web site"

        myMessage.Body = mailBody

        myMessage.To.Add(New MailAddress("cbu@shap.org.uk"))

        Dim mysmtpClient As SmtpClient = New SmtpClient()
        mysmtpClient.Send(myMessage)

    End Sub

    Protected Sub UpdateDatabase()

        Dim ExistingUser As MembershipUser = Membership.GetUser(currentUser)
        Dim UserId As Guid = CType(ExistingUser.ProviderUserKey, Guid)
        Dim SDate As Date = Now()
        Dim FDate As Date = SDate.AddDays(28)

        Dim connection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("LiteratureCataloguingConnectionString").ConnectionString)
        Dim sql As String = "INSERT INTO Loan (PublicationID, UserId, StartLoanDate, EndLoanDate, ThirdDayNotification, FifthDayNotification, FifteenthDayNotification, ThirtiethDayNotification) VALUES (@PublicationID, @UserId, @StartLoanDate, @EndLoanDate, @ThirdDayNotification, @FifthDayNotification, @FifteenthDayNotification, @ThirtiethDayNotification)"

        Dim command As SqlCommand = New SqlCommand(sql, connection)
        command.Parameters.AddWithValue("@PublicationID", PublicationID)
        command.Parameters.AddWithValue("@UserId", UserId)
        command.Parameters.AddWithValue("@StartLoanDate", SDate)
        command.Parameters.AddWithValue("@EndLoanDate", FDate)
        command.Parameters.AddWithValue("@ThirdDayNotification", (0))
        command.Parameters.AddWithValue("@FifthDayNotification", (0))
        command.Parameters.AddWithValue("@FifteenthDayNotification", (0))
        command.Parameters.AddWithValue("@ThirtiethDayNotification", (0))

        command.Connection.Open()
        command.ExecuteNonQuery()
        command.Connection.Close()

        Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
            Dim existingStatus = (From publication In myLiteratureCatalogue.Publications Where publication.PublicationID = (PublicationID) Select publication).First()

            ' Change the status of the publication.
            existingStatus.StatusID = (2)

            myLiteratureCatalogue.SaveChanges()

        End Using

    End Sub

    Protected Sub GridViewReservations_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridViewReservations.RowCommand

        If (e.CommandName = "Cancel") Then

            ' Retrieve the row index stored in the CommandArgument property.
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            ' Retrieve the row that contains the button from the Rows collection.
            Dim row As GridViewRow = GridViewReservations.Rows(index)
            PublicationID = row.Cells(0).Text

            ' Retrieve the row that contains the button from the Rows collection.
            Dim rowTwo As GridViewRow = GridViewReservations.Rows(index)
            Status = rowTwo.Cells(2).Text

            If Status = "Out on Loan\Reserved for Loan" Then

                Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
                    Dim reservationStatus = (From publication In myLiteratureCatalogue.Publications Where publication.PublicationID = (PublicationID) Select publication).First()

                    ' Change the status of the publication.
                    reservationStatus.ReservationID = Nothing
                    reservationStatus.StatusID = (2)

                    myLiteratureCatalogue.SaveChanges()

                End Using

                'System.Threading.Thread.Sleep(5000)
                Call ReservationCancellationNotification()

            ElseIf Status = "Reserved for Loan" Then

                Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
                    Dim reservationStatus = (From publication In myLiteratureCatalogue.Publications Where publication.PublicationID = (PublicationID) Select publication).First()

                    ' Change the status of the publication.
                    reservationStatus.ReservationID = Nothing
                    reservationStatus.StatusID = (1)

                    myLiteratureCatalogue.SaveChanges()

                End Using

                'System.Threading.Thread.Sleep(5000)
                'Response.Redirect(Request.RawUrl)
                Call ReservationCancellationNotification()

            End If

        End If

        If (e.CommandName = "Loan") Then

            ' Retrieve the row index stored in the CommandArgument property.
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)

            ' Retrieve the row that contains the button from the Rows collection.
            Dim row As GridViewRow = GridViewReservations.Rows(index)
            PublicationID = row.Cells(0).Text

            ' Retrieve the row that contains the button from the Rows collection.
            Dim rowOne As GridViewRow = GridViewReservations.Rows(index)
            PubTitle = rowOne.Cells(1).Text

            ' Retrieve the row that contains the button from the Rows collection.
            Dim rowTwo As GridViewRow = GridViewReservations.Rows(index)
            Status = rowTwo.Cells(2).Text

            If Status = "Available for Loan" Then

                Call UpdateDatabase()
                Call UserConfirmation()
                Call CBULoanConfirmation()

                Using myLiteratureCatalogue As New Model1.Literature_Cataloguing_SystemEntities
                    Dim reservationStatus = (From publication In myLiteratureCatalogue.Publications Where publication.PublicationID = (PublicationID) Select publication).First()

                    ' Change the status of the publication.
                    reservationStatus.ReservationID = Nothing
                    reservationStatus.StatusID = (2)

                    myLiteratureCatalogue.SaveChanges()

                End Using

                System.Threading.Thread.Sleep(5000)
                Response.Redirect(Request.RawUrl)

            ElseIf Status = "Out on Loan\Reserved for Loan" Or "Out on Loan" Or "Reserved for Loan" Then


                System.Threading.Thread.Sleep(5000)
                Response.Redirect(Request.RawUrl)

                Stop

            End If

        End If

    End Sub


    Protected Sub ReservationCancellationNotification()

        ' Define the name and type of the client scripts on the page. 
        Dim csname1 As [String] = "PopupScript"
        Dim cstype As Type = Me.[GetType]()

        ' Get a ClientScriptManager reference from the Page class. 
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Check to see if the startup script is already registered. 
        If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
            Dim cstext1 As New StringBuilder()
            cstext1.Append("<script type=text/javascript> alert('This reservation has now been cancelled') </")
            cstext1.Append("script>")

            cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
        End If

    End Sub

End Class
Reply With Quote
  #14 (permalink)  
Old May 3rd, 2011, 12:43 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

BTW, are you running this from within an UpdatePanel?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #15 (permalink)  
Old May 3rd, 2011, 12:47 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Update Panel

Hi Imar

Yes its inside an update panel? Is that a no no for this functionality?
Reply With Quote
  #16 (permalink)  
Old May 3rd, 2011, 01:00 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
Is that a no no for this functionality?
No, but it means you need to call the register script differently For more details:

http://developers.de/blogs/damir_dob...3F002100_.aspx
http://www.google.com/#hl=en&sugexp=...pt+Updatepanel


Then replace the code with something like this (untested):
Code:
 
Protected Sub ReservationCancellationNotification()
  ScriptManager.RegisterStartupScript(Page, Page.GetType(), "PopupScript", "alert('This reservation has now been cancelled.')", True)
End Sub
A few remarks:

1. Call is no longer needed. It was in Classic ASP, but now it serves no purpose.
2. When assigning script in a literal, using "<scr" & "ipt>" is no longer needed. It was in classic ASP as it would close the opening server side script tag.
3. Dotting into object references is no longer that expensive. E.g.:

Code:
 
Page.ClientScript.RegisterStartupScript(...)
is cleaner IMO than:

Code:
 
Dim cs As ClientScriptManager = Page.ClientScript
cs.RegisterStartupScript(...)
4. RegisterStartupScript has an overload that accepts a bool (used in my example) that automatically adds the necessary script tags for you.

There are some other recommendations I could make, but this should keep you busy for a while ;-)

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #17 (permalink)  
Old May 3rd, 2011, 01:00 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Error Message

Since taking off the Update Panel I get the error code as shown below:


Server Error in '/' Application.
________________________________________
The GridView 'GridViewReservations' fired event RowCancelingEdit which wasn't handled.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The GridView 'GridViewReservations' fired event RowCancelingEdit which wasn't handled.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The GridView 'GridViewReservations' fired event RowCancelingEdit which wasn't handled.]
System.Web.UI.WebControls.GridView.OnRowCancelingE dit(GridViewCancelEditEventArgs e) +279
System.Web.UI.WebControls.GridView.HandleCancel(In t32 rowIndex) +67
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean causesValidation, String validationGroup) +973
System.Web.UI.WebControls.GridView.RaisePostBackEv ent(String eventArgument) +211
System.Web.UI.WebControls.GridView.System.Web.UI.I PostBackEventHandler.RaisePostBackEvent(String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5348
Reply With Quote
  #18 (permalink)  
Old May 3rd, 2011, 01:03 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

For that error, see:

http://www.google.com/#q=%22event%20...t%20handled%22

Also, you may need to call DataBind on your GridView after you canceled the reservation to rebind the Grid.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #19 (permalink)  
Old May 3rd, 2011, 01:06 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default Dead Link

Hi Imar

can you repost this http://www.google.com/#q=%22event%20...t%20handled%22 as the link is just direct to Google and no actual search reference?

Thank you for all your help its much appreciated!

Phil
Reply With Quote
  #20 (permalink)  
Old May 3rd, 2011, 01:25 PM
Authorized User
 
Join Date: Feb 2011
Posts: 37
Thanks: 8
Thanked 0 Times in 0 Posts
Default IT WORKS!!!!

Hi Imar

THANK YOU LOADS!!! It finally works I've been pulling my hair out for days trying to get this to work and now it finally does!

I glad this resource is available to people like me who are just starting to venture into the world of ASP development without it we would all be stumped, well I know I would!

Thanks once again!

Phil
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't find control in GridView RowCommand rsearing ASP.NET 2.0 Professional 8 September 10th, 2011 07:10 PM
The GridView 'GridView' fired event PageIndexChanging which wasn't handled Phil Critchley ASP.NET 4 General Discussion 10 February 19th, 2011 09:55 AM
Javascript functions and xslt 1.0 variable mlohokare XSLT 18 December 3rd, 2008 02:22 AM
Executing from JavaScript C# functions see07 ASP.NET 1.x and 2.0 Application Design 1 March 1st, 2005 07:02 PM
javascript functions Moharo Javascript 1 September 23rd, 2003 01:04 AM



All times are GMT -4. The time now is 11:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.