I have a a Gridview which displays records (training) of various individuals! When you click on the various cells an AJAX ModelPopUpextender opens showing further details relating to that particular training sets!
The problem I'm having is that when I click on any of the GridView cells and the ModelPopUp opens the Gridview PostsBack. Id like to be able to click on any cell and get the same functinality without the Gridview posting back?
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
For Each r As GridViewRow In GridView1.Rows
If r.RowType = DataControlRowType.DataRow Then
For columnIndex As Integer = 0 To r.Cells.Count - 1
Page.ClientScript.RegisterForEventValidation(r.UniqueID + "$ctl00", columnIndex.ToString())
Next
End If
Next
MyBase.Render(writer)
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim _singleClickButton As LinkButton = DirectCast(e.Row.Cells(0).Controls(0), LinkButton)
Dim _jsSingle As String = ClientScript.GetPostBackClientHyperlink(_singleClickButton, "")
' Add events to each editable cell
For columnIndex As Integer = 2 To e.Row.Cells.Count - 1
' Add the column index as the event argument parameter
Dim js As String = _jsSingle.Insert(_jsSingle.Length - 2, columnIndex.ToString())
' Add this javascript to the onclick Attribute of the cell
e.Row.Cells(columnIndex).Attributes("onclick") = js
' Add a cursor style to the cells
e.Row.Cells(columnIndex).Attributes("style") += "cursor:pointer;cursor:hand;"
Next
End If
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName.ToString() = "CellClick" Then
Dim selectedRowIndex As Integer = Convert.ToInt32(e.CommandArgument.ToString())
Dim selectedColumnIndex As Integer = Convert.ToInt32(Request.Form("__EVENTARGUMENT").ToString())
Dim ServiceNo As String = GridView1.HeaderRow.Cells(selectedColumnIndex).Text.Remove(4)
Dim TrainingId As String = GridView1.Rows(selectedRowIndex).Cells(selectedColumnIndex).Text.Remove(0, 1)
If TrainingId = "nbsp;" Or TrainingId = String.Empty Then
Else
ModalPopupExtender1.Show()
'Get the Distinct users in the roles nlAdmin and nlUser
Dim strQuery As String = "SELECT string goes here)"
Dim cmd As New SqlCommand(strQuery)
cmd.Parameters.AddWithValue("@tt_id", TrainingId.ToString)
Dim dt As DataTable = GetData(cmd)
DetailsView1.DataSource = dt
DetailsView1.DataBind()
End If
End If
End Sub
You will need to change your design a little. With your current design the postback is required in order to populate the fields in the popup. If you want to eliminate a trip to the server, then these fields need to be populated when the GrdiView is data
bound. You can do this by using template columns and declaring the Panel control which will be used for the popup and adding a ModalPopupExtender. Each row of your GridView will then have a Panel control and a ModalPopupExtender declared.
If your issue is not the trip to the server but a full screen redraw, then you can use an UpdatePanel or just handle the trip to the server with a client side function which makes an Ajax request, populates the fields in the popup and shows the popup by
calling the ModalPopupExtenders client side show() function.
Hi RichardY not sure the first part of this (changing the design a little , paragraph 1) is feasible! As theres a lot of other things going on in the page which is affected by the use of the datatable in a Gridview method!
With the present design when the gridview is bound, when a cell is clicked I need to exclude the Gridview from postback!
The second paragraph seems to be a possiblity! Do you know of any good examples which would clarify this for me?
As RichardY mentioned, you should do a post back because you want populate data to the DetailsView in the pop up.
If you do not want a full post back, you can use ajax to call the server and request the fields data. Then open the
ModalPopupExtender using javascript.
Thanks a lot for all the help however I fould out what the problem was!
As you can see the code created worked well but i was having touble with postback. Previously trying to use the trigger I was trying to use the buttonfield
I was unable to achieve what i wanted this way as the trigger wouldn't work directly with a buttonfield. I also tried to change the buttonfield to a linkbutton in a templatfield but this produced the wrong outcomes!
However the solution WAS to use asyncpostbacktrigger! Instead of trying to find a way of using (finding) the buttonfield ID (controlid) and the eventname (CellClick) on the buttonfield I used the gridview GridView1 as the controlid and rowcommand as the
eventname
Member
14 Points
281 Posts
Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 17, 2014 06:45 AM|I-Weedy|LINK
I have a a Gridview which displays records (training) of various individuals! When you click on the various cells an AJAX ModelPopUpextender opens showing further details relating to that particular training sets!
The problem I'm having is that when I click on any of the GridView cells and the ModelPopUp opens the Gridview PostsBack. Id like to be able to click on any cell and get the same functinality without the Gridview posting back?
ajaxToolkit modelPopup gridview asp.net
Contributor
6874 Points
1980 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 17, 2014 01:45 PM|RichardY|LINK
You will need to change your design a little. With your current design the postback is required in order to populate the fields in the popup. If you want to eliminate a trip to the server, then these fields need to be populated when the GrdiView is data bound. You can do this by using template columns and declaring the Panel control which will be used for the popup and adding a ModalPopupExtender. Each row of your GridView will then have a Panel control and a ModalPopupExtender declared.
If your issue is not the trip to the server but a full screen redraw, then you can use an UpdatePanel or just handle the trip to the server with a client side function which makes an Ajax request, populates the fields in the popup and shows the popup by calling the ModalPopupExtenders client side show() function.
ajaxToolkit modelPopup gridview asp.net
All-Star
48393 Points
12161 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 17, 2014 10:44 PM|chetan.sarode|LINK
http://mattberseth.com/blog/2008/06/masterdetail_with_the_gridview_1.html
ajaxToolkit modelPopup gridview asp.net
Team Lead, Product Development
Approva Systems Pvt Ltd, Pune, India.
Member
14 Points
281 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 18, 2014 12:07 PM|I-Weedy|LINK
Hi RichardY not sure the first part of this (changing the design a little , paragraph 1) is feasible! As theres a lot of other things going on in the page which is affected by the use of the datatable in a Gridview method!
With the present design when the gridview is bound, when a cell is clicked I need to exclude the Gridview from postback!
The second paragraph seems to be a possiblity! Do you know of any good examples which would clarify this for me?
ajaxToolkit modelPopup gridview asp.net
Member
14 Points
281 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 18, 2014 12:11 PM|I-Weedy|LINK
Hi Chetan, not really sure how 'thickbox' helps the situation?
ajaxToolkit modelPopup gridview asp.net
All-Star
30411 Points
3628 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 20, 2014 03:25 AM|Fuxiang Zhang - MSFT|LINK
Hi I-Weedy,
Thank you post the issue to our forum.
As RichardY mentioned, you should do a post back because you want populate data to the DetailsView in the pop up.
If you do not want a full post back, you can use ajax to call the server and request the fields data. Then open the ModalPopupExtender using javascript.
http://blogs.msdn.com/b/phaniraj/archive/2007/02/20/show-and-hide-modalpopupextender-from-javascript.aspx
In my mind, I think it is a better solution provided by RichardY. And your code is also works good.
Thanks.
Best Regards!
ajaxToolkit modelPopup gridview asp.net
Member
14 Points
281 Posts
Re: Stop AutoPostback on Gridview cell click when ModelPopUpExtender opens
Feb 20, 2014 12:01 PM|I-Weedy|LINK
Hi,
Thanks a lot for all the help however I fould out what the problem was!
As you can see the code created worked well but i was having touble with postback. Previously trying to use the trigger I was trying to use the buttonfield
I was unable to achieve what i wanted this way as the trigger wouldn't work directly with a buttonfield. I also tried to change the buttonfield to a linkbutton in a templatfield but this produced the wrong outcomes!
However the solution WAS to use asyncpostbacktrigger! Instead of trying to find a way of using (finding) the buttonfield ID (controlid) and the eventname (CellClick) on the buttonfield I used the gridview GridView1 as the controlid and rowcommand as the eventname
also using
on the Modelpopupextender to close the popup.
Works a charm.
Once again thanks for your help
ajaxToolkit modelPopup gridview asp.net