How to create a dynamic url for radsocialshare facebook button?
i have a radsocialshare facebook like button in radgrid items i want when i click on like button of radgrid item the item url will be share in facebook as ~/page.aspx?id=1
Note : ID will be auto generated according to the radgrid items
Either bind the control's UrlToShare property (e.g. in the ItemDataBound event) which is easier, or set it on the client (in this case you cannot use ~/ for the root, you need a client-usable URL) if you have only one instance above/below the grid.
In the radgrid's ItemCreated event, you can set the UrlToShare property like so:
Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemCreated
Dim RadSocialShare1 As RadSocialShare = e.Item.FindControl("RadSocialShare1")
If RadSocialShare1 IsNot Nothing Then
'In this example, "ID" is a field in the data bound to the radgrid
Dim myID as string = DataBinder.Eval(e.Item.DataItem, "ID")
'Now Make the Url
Dim myUrl as string = "~/page.aspx?id=" & myID
RadSocialShare1.UrlToShare = myUrl
End If
End Sub
Related
Is there some way to trap/get the value that a Data Pager advances to on the button click for Next or Previous record when navigating a ListView control?
And what about telling the pager which page to display programmatically?
you should use the PagePropertiesChanging event to get current page
Protected Sub ListView1_PagePropertiesChanging(sender As Object, e As PagePropertiesChangingEventArgs)
Dim CurrentPage As Integer = (e.StartRowIndex / e.MaximumRows) + 1
Response.Write(CurrentPage.ToString())
End Sub
I need to add a confirm delete action to a grid. the problem is the way the "Delete" link is rendered.
my grid is built in code behind in vb.net.
i have this
colDelete.AllowDelete = True
colDelete.Width = "100"
AddHandler CType(gridSavedForLater, Grid).DeleteCommand, AddressOf dgDeleteSelectedIncident
and the sub is the following
Sub dgDeleteSelectedIncident(ByVal sender As Object, ByVal e As GridRecordEventArgs)
Dim message As String = "Are you sure you want to delete this incident?"
Dim caption As String = "Confirm Delete"
Dim result = System.Windows.Forms.MessageBox.Show(message, caption, Windows.Forms.MessageBoxButtons.OKCancel, Windows.Forms.MessageBoxIcon.Warning)
'If (result = Windows.Forms.DialogResult.Cancel) Then
'Else
' MessageBox("Are you sure you want to delete this incident?")
'Get the VehicleId of the row whose Delete button was clicked
'Dim SelectedIncidentId As String = e.Record("IncidentId")
''Delete the record from the database
'objIncident = New Incidents(SelectedIncidentId, Session("userFullName"))
'objIncident.DeleteIncident()
''Rebind the DataGrid
LoadSavedForLater()
'' End If
End Sub
i need to add a javascript confirm dialog when this sub is called. i can do it with a windows form messagebox but that does not work on the server.
pleae help
joe
You cannot show a MessageBox in ASP.NET since it would be shown on the server. So you need a javascript confirm onclick of the delete button. Therefor you don't need to postback to the server first. You can attach the script on the initial load of the GridView.
A good place would be in RowDataBound of the GridView:
Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.DataRow
' if it's a custom button in a TemplateField '
Dim BtnDelete = DirectCast(e.Row.FindControl("BtnDelete"), Button)
BtnDelete.OnClientClick = "return confirm('Are you certain you want to delete?');"
' if it's an autogenerated delete-LinkButton: '
Dim LnkBtnDelete As LinkButton = DirectCast(e.Row.Cells(0).Controls(0), LinkButton)
LnkBtnDelete.OnClientClick = "return confirm('Are you certain you want to delete?');"
End Select
End Sub
As an alternative, a common method of notifying users in a web page of a status change (save, delete, update, etc.) is having an update element in your HTML. Basically, a label (or whatever) that you'll set with updates to the user.
"Your changes have been successfully saved." or "An error was encountered when trying to save your update.", for example. You can set the color red for an error or whatever your programming heart desires, stylistically.
I kind of like this approach as a pop-up always feels more like a WinForm thing to me. Either works, so I just thought I'd suggest another approach.
The code below displays a thumbnail of each image in a specific server directory and when I click on the image it pops up a nice full sized picture. It works perfectly.
I would however, like to be able to delete an image. I first thought I could have a button at the bottom of the page with a checkbox next to each image, giving it a uniqueID as per the filename but as they are dynamically created I couldn’t figure how to handle the Click Event on the button for a randomly named Checkbox ID. Then I tried adding a button next to each item and then tried an OnClick & OnServerClick to call a Sub but this didn’t work either.
Any/All suggestions welcomed :)
Private Sub ImageList()
If Directory.Exists(Server.MapPath("JobImages\" & DBC_JOB_JobID.Text)) Then
Dim MySB As New StringBuilder
Dim dirInfo As New DirectoryInfo(Server.MapPath("JobImages\" & DBC_JOB_JobID.Text))
MySB.Append("<ul class=""clearfix"">")
MySB.AppendLine()
For Each File In dirInfo.GetFiles()
MySB.Append("<li><a rel=""jobpic"" href=""JobImages\" & DBC_JOB_JobID.Text & "\" & File.Name & """><img src=""JobImages\" & DBC_JOB_JobID.Text & "\Thumbs\" & File.Name & """ width=""150"" height=""100"" /> <span class=""size"">" & File.Name & " </span></a></li>")
MySB.AppendLine()
Next
MySB.Append("</ul>")
MySB.AppendLine()
lblMyPictures.Text = MySB.ToString
End If
End Sub
OK what Kendrick is talking about (basically) is using server side controls to keep track of which file to delete. What you are doing right now is dumping markup into a Label control, which on postback won't fire an event on the server side. However you can accomplish this easily with server side controls.
The basic idea is you use a container control such as a Panel and add each child control to it. Then you hook events to each row with data identifying that row (such as filename).
Markup:
<asp:Panel ID="pnlList" runat="server">
</asp:Panel>
Code-Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Directory.Exists(Server.MapPath("Files")) Then
Dim objDirInfo As New DirectoryInfo(Server.MapPath("Files"))
For Each objFile As FileInfo In objDirInfo.GetFiles()
Dim objLabel As New Label
objLabel.Text = objFile.Name
Dim objLinkButton As New LinkButton
objLinkButton.Text = "Delete"
objLinkButton.CommandName = "Delete"
objLinkButton.CommandArgument = objFile.Name
AddHandler objLinkButton.Command, AddressOf DeleteFile
Dim objLiteral As New LiteralControl
objLiteral.Text = "<br/>"
pnlList.Controls.Add(objLabel)
pnlList.Controls.Add(objLinkButton)
pnlList.Controls.Add(objLiteral)
Next
End If
End Sub
Public Sub DeleteFile(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
If e.CommandName = "Delete" Then
Dim strFileName As String = Server.MapPath("Files\" & e.CommandArgument)
If File.Exists(strFileName) Then
Dim objFile As New FileInfo(strFileName)
objFile.Delete()
End If
End If
End Sub
This would be an excellent example of where using a data aware would make your life a lot easier.
That said, if you didn't want to use a server-side control, you could assign an ID to each checkbox (i.e. DeleteImage_1) and then store the ID and associated image name in the viewstate on the page. Go through the checked checkboxes and refer back to the viewstate for the name that goes with each ID when they click the delete button.
I have GridView control in my asp.net page with auto generated fields
there is only footer template is present under asp:TemplateField.
I can bind this gridview with any of databae table as depend on user
selection. Now want to add new record in database so I have added text
boxes on footer template cells at runtime depend on number of columns
on table. But when I accessing these text boxes from footer template
on gridview_RowCommand event its not retriving textbox control.
this is the code:
SGridView.ShowFooter = True
For i As Integer = 0 To ctrList.Count
Dim ctr As Control = CType(ctrList.Item(i), Control)
SGridView.FooterRow.Cells(i + 1).Controls.Add(ctr)
Next
the ctrList contain Controls textBox, checkbox dropdowlist ect.
there is all ok
but when i wont to get the text or value or checked value of controls i can't cast the controls in rowcommand event
Here is the code:
If e.CommandName = "Add" Then
Dim ctrList As ControlCollection = SGridView.FooterRow.Controls
For Each ctr As Control In ctrList
If TypeOf ctr Is TextBox Then
Dim name As TextBox = CType(ctr, TextBox)
Dim val As String = name.Text
End If
Next
End If
this excample is for the textBox control.
Plese suggest me how can I get footer control textboxes. So that I can
save data in database.
When you are dealing with Dynamic controls you have to keep a close eye on the .net page lifecycle.
Control data is bound in the Load event, so your not able to access postback data in that event when your doing your conrol generation in the Load event too. I usualy try to create dynamic controls in the Init of the page, and do any values processing on the LoadComplete or PreRender event so I can make sure they have recieved their values from the postback before you try to read them.
Take a look at the full description of the ASP.NET page lifecycle events and whats going on. This should help you navigate the creation and use of Dynamic generated controls.
Try to create your Controls in the Grdiview's RowCreated Event which will be raised on every Postback.
Private Sub Grid1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Grid1.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Footer
'add controls to row
End Select
End Sub
I have a custom control that inherits from .NET's CompositeControl class. This control overrides the CreateChildControls in order to build its child controls dynamically. I need the page to post back after a couple different javascript events occur on the client side.
In order to accomplish this, I create two hidden controls on the page so I can set their values with javascript, submit the page, and read the values out on server side. Here's is the code I use to create these two hiddens:
Protected Overrides Sub CreateChildControls()
hdEventName = New HiddenField()
Controls.Add(hdEventName)
hdEventName.ID = "hdEventName"
hdEventArgs = New HiddenField()
Controls.Add(hdEventArgs)
hdEventArgs.ID = "hdEventValue"
' other controls
' ...
End Sub
When a javascript event occurs I set the value attribute of the two hiddens and submit the page, like so:
hdEventName.value = 'EventName';
hdEventArgs.value = 'arg1,arg2';
document.forms[0].submit();
In the OnLoad method of my control, I attempt to check the Value property of the hdEventName and hdEventArgs controls, but it is always empty. However, Page.Request.Form(hdEventName.UniqueID) and Page.Request.Form(hdEventArgs.UniqueID) return correct values. The actual HTML in the markup also shows correct values after the page posts back.
Why is the Value property of the HtmlInputHiddens disconnected from the actual value that appears on the client?
Update
It appears that a control's properties get loaded from the form sometime after OnLoad occurs. Thus I was able to solve my problem by either moving the code that checks the two hidden fields into the OnPreRender method, or adding the following method to my code -
Private Sub Event_Handler(ByVal sender As Object, ByVal e As EventArgs)
Handles hdEventName.ValueChanged
' do stuff with hiddens
' ...
' reset the values back
hdEventName.Value = String.Empty
hdEventArgs.Value = String.Empty
End Sub
when the page posts back there's nothing to link the variable hdEventName to the control you previously created. what you're doing is akin to having an integer declared at the class level and setting it to 5 when you're creating child controls. there's nothing to maintain that value in that variable across postbacks.
if you want to get a reference to the control you created previously, you'd have to use
hdEventName = CType(Page.FindControl("hdEventName") , HiddenField)
(i'm guessing at this) or Request if you're only concerned with the value.
It appears that a control's properties get loaded from the form sometime after OnLoad occurs. Thus I was able to solve my problem by either moving the code that checks the two hidden fields into the OnPreRender method, or adding the following method to my code -
Private Sub Event_Handler(ByVal sender As Object, ByVal e As EventArgs)
Handles hdEventName.ValueChanged
' do stuff with hiddens
' ...
' reset the values back
hdEventName.Value = String.Empty
hdEventArgs.Value = String.Empty
End Sub