2014年7月13日 星期日

[RESOLVED] My Gridview Delete Button Works with IE but not with Chrome


I am using VS 2010 to create my application.  I have a gridview with a delete button that works as expected when deployed when I test it in my IE9 Browser but fails when I test it in a Chrome browser.  Is there a workaround for this apparent chrome/.net
incompatability?  I appreciate any ideas, suggestions, etc. you care to offer........................Phil Hoop


********************Partial listing of code*******************************************************************


<ItemTemplate>


<asp:LinkButton
ID="LinkButton1"
runat="server"
CausesValidation="False"
CommandName="Edit"
Text="Edit">asp:LinkButton>


 <asp:LinkButton
ID="LinkButton2"
runat="server"
CausesValidation="False"
CommandName="Delete"
Text="Delete"
OnClientClick="return
confirm('Are you sure you want to delete this record?');">
asp:LinkButton>


ItemTemplate>




Honestly, I don't know if there's much we can tell you based on what you have shown us.  What portion of it fails?  When I add your code into a test app and run it in Chrome it appears to be running as expected.  This has just a txt_id (pk in the Table)
and text field (varchar(50))


Working GridView code in Chrome:











 
























Speshulk925:  Thanks for your post.  Actually you have done an excellent job of condensung my situation to what I think are the basic elements.  In my case, when I click the delete button (using the Chrome browser), the alert message appears as expected,
but when I click OK nothing happens.  I will post the entire html as well as the code behind..  Based on what you have showed  in your condensation, I'm really puzzled.  The code below works well with IE9 but fails with chrome.  I have a number of pages in
my application with gridviews all of which exhibit this same discrepancy between IE9 and Chrome.  I'd appreciate your review of the code below.  My intuition makes me think that the Script Manager (for the validators) might be a player in this puzzle.  Thank
you very much...........Phil Hoop


***********Page Definition************************************************************************ 


<%@
Page
Title=""
Language="vb"
MaintainScrollPositionOnPostBack="True"
AutoEventWireup="false"


MasterPageFile="~/Booster.Master"
CodeBehind="Activity_Groups.aspx.vb"


Inherits="BetterBoosters.WebForm15"
Theme="GridviewTheme"
%>


<asp:Content
ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">


<asp:ScriptManager
ID="ScriptManager1"
runat
=
"server"
/>


<asp:Label
ID="Label2"
runat="server"
Text="Custom
Groups"

CssClass="stylelabelunderline">asp:Label>  


<br
/>


<br
/>


<asp:Label
ID="LabelError"
runat="server"
Visible="False"
ForeColor="Red"
Font-Size="Large"
EnableViewState="False">asp:Label>


<asp:GridView
ID="GridView1"
runat="server"
AllowSorting="True"


AutoGenerateColumns="False"
DataKeyNames="GroupID"


DataSourceID="SqlDataSource1"
SkinID="Standard"
Width="60%"


AllowPaging="True"
PageSize="15"
EmptyDataText="There
are not any custom groups entered yet.">


<Columns>


<asp:BoundField
DataField="GroupID"
HeaderText="GroupID"
InsertVisible="False"


ReadOnly="True"
SortExpression="GroupID"
Visible="False"
/>


<asp:TemplateField
HeaderText=""
SortExpression="GroupPart1"
ItemStyle-Width="38%"
>


<EditItemTemplate>


<asp:TextBox
ID="txtGroupPart1"
runat="server"
Text='<%#
Bind("GroupPart1") %>
'
Width="100%"
BorderStyle="None"
BackColor="#FFFF99">asp:TextBox>


EditItemTemplate>


<ItemTemplate>


<asp:Label
ID="txtGroupPart1"
runat="server"
Text='<%#
Bind("GroupPart1") %>
'
Width="100%"
>asp:Label>


ItemTemplate>


<ItemStyle
Width="38%">ItemStyle>


asp:TemplateField>


<asp:TemplateField
HeaderText="Part
2"

SortExpression="GroupPart2" 
ItemStyle-Width="40%"
Visible="False">


<EditItemTemplate>


<asp:TextBox
ID="TextBox2"
runat="server"
Text='<%#
Bind("GroupPart2") %>
'
Width="100%"
BorderStyle="None"
BackColor="#FFFF99">asp:TextBox>


EditItemTemplate>              


<ItemTemplate>


<asp:Label
ID="Label2"
runat="server"
Text='<%#
Bind("GroupPart2") %>
'
Width="100%">asp:Label>


ItemTemplate>


<ItemStyle
Width="40%">ItemStyle>


asp:TemplateField>


<asp:TemplateField
HeaderText="Sequence"
SortExpression="SortSequence"
ItemStyle-Width="10%">


<EditItemTemplate>


<asp:TextBox
ID="TextBox3"
runat="server"
Text='<%#
Bind("SortSequence") %>
'
Width="100%"
BorderStyle="None"
BackColor="#FFFF99">asp:TextBox>


EditItemTemplate>


<ItemTemplate>


<asp:Label
ID="Label3"
runat="server"
Text='<%#
Bind("SortSequence") %>
'
Width="100%"
>asp:Label>


ItemTemplate>


<ItemStyle
Width="10%"
/>


asp:TemplateField>


<asp:TemplateField
ShowHeader="False"
ItemStyle-Width="12%">


<EditItemTemplate>


<asp:LinkButton
ID="LinkButton1"
runat="server"
CausesValidation="True"


CommandName="Update"
Text="Update">asp:LinkButton>


 <asp:LinkButton
ID="LinkButton2"
runat="server"
CausesValidation="False"


CommandName="Cancel"
Text="Cancel">asp:LinkButton>


EditItemTemplate>


<ItemTemplate>


<asp:LinkButton
ID="LinkButton1"
runat="server"
CausesValidation="False"


CommandName="Edit"
Text="Edit">asp:LinkButton>


 <asp:LinkButton
ID="LinkButton2"
runat="server"
CausesValidation="False"


CommandName="Delete"
Text="Delete"


OnClientClick="return
confirm('Are you sure you want to delete this record?');">
asp:LinkButton>


ItemTemplate>


<ItemStyle
Width="12%">ItemStyle>


asp:TemplateField>


Columns>


asp:GridView>


<asp:Button
ID="btnAdd"
runat="server"
Text="Add
Group"

Visible="True"
/>


<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"


ConnectionString="<%$
ConnectionStrings:ApplicationServices %>
"


DeleteCommand="DELETE
FROM [vwGroupsType2] WHERE [GroupID] = @GroupID"


SelectCommand="SELECT
[GroupID], [GroupTypeID], [GroupPart1], [GroupPart2], [SortSequence], [Inactive] FROM [vwGroupsType2] ORDER BY [SortOrder1], [SortSequence]"


UpdateCommand="UPDATE
[vwGroupsType2] SET [GroupPart1] = @GroupPart1,


            [GroupPart2] = @GroupPart2, [SortSequence] = @SortSequence


            WHERE [GroupID] = @GroupID">


<DeleteParameters>


<asp:Parameter
Name="GroupID"
Type="Int32"
/>


DeleteParameters>


<UpdateParameters>


<asp:Parameter
Name="GroupID"
Type="Int32"
/>


<asp:Parameter
Name="GroupPart1"
Type="String"
/>


<asp:Parameter
Name="GroupPart2"
Type="String"
/>


<asp:Parameter
Name="SortSequence"
Type="Int32"
/>


UpdateParameters>


asp:SqlDataSource>


<asp:SqlDataSource
ID="SqlDataSource2"
runat="server"


ConnectionString="<%$
ConnectionStrings:ApplicationServices %>
"


SelectCommand="SELECT
[GroupTypeID], [GroupType] FROM [vwGroupTypeDropdown] ORDER BY [GroupTypeID]">


asp:SqlDataSource>


<br
/>


asp:Content>


*************************Code
Behind*****************************************************


Imports
System


Imports
System.Data


Imports
System.Data.SqlClient


Imports
System.Configuration


Public
Class

WebForm15


Inherits
System.Web.UI.
Page


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


End
Sub


Private
Sub
btnAdd_Click(sender
As
Object,
e
As
System.
EventArgs)
Handles
btnAdd.Click


If
Me.GridView1.EditIndex
<> -1
Then


Me.GridView1.UpdateRow(Me.GridView1.EditIndex,
True)


End
If


'Fetch
the connection string from web.config


Dim
connstring
As
String
=
ConfigurationManager.ConnectionStrings("ApplicationServices").ConnectionString


Dim
strQuery
As
String
=
"INSERT
INTO vwGroupsAdd (GroupTypeID) VALUES (2);"


Using
conn
As
New
SqlConnection(connstring)


 conn.Open()


'initialize
command object


Using
cmd
As
New
SqlCommand(strQuery,
conn)


 cmd.ExecuteNonQuery()


End
Using


 conn.Close()


End
Using


Me.GridView1.DataBind()


Dim
intNumRecords
As
Integer
=
Me.GridView1.Rows.Count


Me.GridView1.EditIndex
= intNumRecords - 1


End
Sub


Protected
Overrides
Sub
Render(writer
As
System.Web.UI.
HtmlTextWriter)


For
Each
row
As
GridViewRow
In
GridView1.Rows


If
row.RowType =
DataControlRowType.DataRow
AndAlso
row.RowState.HasFlag(
DataControlRowState.Edit)
=
False
Then


'enable
click on row to enter edit mode


 row.Attributes("onclick")
= ClientScript.GetPostBackClientHyperlink(GridView1,
"Edit$"
+ row.RowIndex.ToString(),
True)


End
If


Next


MyBase.Render(writer)


End
Sub


Private
Sub
GridView1_RowDataBound(sender
As
Object,
e
As
System.Web.UI.WebControls.
GridViewRowEventArgs)
Handles
GridView1.RowDataBound


If
GridView1.EditIndex <> -1
AndAlso
e.Row.RowIndex = GridView1.EditIndex
Then


 e.Row.FindControl("txtGroupPart1").Focus()


End
If


End
Sub


Private
Sub
SqlDataSource1_Deleted(sender
As
Object,
e
As
System.Web.UI.WebControls.
SqlDataSourceStatusEventArgs)
Handles
SqlDataSource1.Deleted


Dim
errDeleted
As
String
=
"There
was an error deleting this group.  This group may have individuals assigned to it."


Dim
errContinuation
As
String
= vbCrLf &
"Please
try again.  If this error recurs, please notify your administrator."


Dim
errMessage = errDeleted & errContinuation


If
Not
e.Exception
Is
Nothing
Then


  MsgBox(errMessage,MsgBoxStyle.OkOnly,
"Error
Message"
)


 e.ExceptionHandled =True


End
If


End
Sub


Private
Sub
SqlDataSource1_Updated(sender
As
Object,
e
As
System.Web.UI.WebControls.
SqlDataSourceStatusEventArgs)
Handles
SqlDataSource1.Updated


Dim
errUpdated
As
String
=
"There
was an error updating this group."


Dim
errContinuation
As
String
= vbCrLf &
"Please
try again.  If this error recurs, please notify your administrator."


Dim
errMessage = errUpdated & errContinuation


If
Not
e.Exception
Is
Nothing
Then


 MsgBox(errMessage,

MsgBoxStyle
.OkOnly,
"Error
Message"
)


 e.ExceptionHandled =True


End
If


End
Sub


Private
Sub
SqlDataSource1_Selected(sender
As
Object,
e
As
System.Web.UI.WebControls.
SqlDataSourceStatusEventArgs)
Handles
SqlDataSource1.Deleted


Dim
errSelected
As
String
=
"There
was an error selecting a group."


Dim
errContinuation
As
String
= vbCrLf &
"Please
try again.  If this error recurs, please notify your administrator."


Dim
errMessage = errSelected & errContinuation


If
Not
e.Exception
Is
Nothing
Then


 MsgBox(errMessage,MsgBoxStyle.OkOnly,
"Error
Message"
)


 e.ExceptionHandled =True


End
If


End
Sub


Private
Sub
SqlDataSource1_Inserted(sender
As
Object,
e
As
System.Web.UI.WebControls.
SqlDataSourceStatusEventArgs)
Handles
SqlDataSource1.Deleted


Dim
errInserted
As
String
=
"There
was an error inserting a group."


Dim
errContinuation
As
String
= vbCrLf &
"Please
try again.  If this error recurs, please notify your administrator."


Dim
errMessage = errInserted & errContinuation


If
Not
e.Exception
Is
Nothing
Then


MsgBox(errMessage,MsgBoxStyle.OkOnly,
"Error
Message"
)


e.ExceptionHandled =True


End
If


End
Sub


End
Class





Speshulk925:  I have commented out everything but the gridview, master page, and SqlDataSource.  All of the codebehind is also commented out, and I still get the desired behavior from IE9 and the undesired behavior from Chrome.  Any ideas?  At this point
I think that the version of chrome I am using simply will not work with a simple gridview and its delete button - I am using the latest version of chrome which I downloaded/installed yesterday.  I definitely appreciate you interest and ideas.  Thank you.  
...........................Phil Hoop



Speshulk925:  I found the problem.  When I removed the following code and remembered to
rebuild my application it now works with chrome.  Now I have to develop a different method to get the functionality it provided, this should be reasonably easy.  Thank you for your assistance. 
.......................Phil Hoop


Protected
Overrides

Sub
Render(writer
As
System.Web.UI.
HtmlTextWriter)


For
Each
row
As
GridViewRow
In
GridView1.Rows


If
row.RowType =
DataControlRowType.DataRow
AndAlso
row.RowState.HasFlag(
DataControlRowState.Edit)
=
False
Then


'enable
click on row to enter edit mode


                row.Attributes("onclick")
= ClientScript.GetPostBackClientHyperlink(GridView1,
"Edit$"
+ row.RowIndex.ToString(),
True)


End
If


Next


MyBase.Render(writer)


End
Sub



 


 



I am having the same problem philhoop!


How did you fix this?


沒有留言:

張貼留言