I have a function loadList() that loads a dynamic list based on our database.
In element_maint.aspx.vb:
Private Sub loadList()
'load sub-organizations
Dim lstItems As cihElementList = Nothing
Dim thr As TableHeaderRow = Nothing
Dim tr As TableRow = Nothing
Dim tc As TableCell = Nothing
Dim lnk1 As HyperLink = Nothing
Dim lnk2 As HyperLink = Nothing
Dim item As cihCategoryOrgDef = Nothing
Dim rvd As Routing.RouteValueDictionary = Nothing
Dim rvdDeactivate As Routing.RouteValueDictionary = Nothing
Dim vpd As Routing.VirtualPathData = Nothing
Dim vpdDeactivate As Routing.VirtualPathData = Nothing
Dim btnAction As cihBootstrapButtonDropdown = Nothing
'*****************************************
'Build the action drop down
'Build the action button
'*****************************************
btnAction = New cihBootstrapButtonDropdown("Action", cihBootstrapButtonDropdown.buttonTypes.link)
'Existing Items
lstItems = New cihElementList()
lstItems.loadForOrganization(orgId)
For Each ele As cihElementList.elementShort In lstItems.listOfElements
tr = New TableRow
lnk1 = New HyperLink
lnk1.Text = "Edit"
lnk2 = New HyperLink
lnk2.Text = "Deactivate"
rvd = New Routing.RouteValueDictionary(New With {.action = "edit", .elementid = ele.elementId.ToString()})
rvdDeactivate = New Routing.RouteValueDictionary(New With {.action = "deactivate", .elementid = ele.elementId.ToString()})
vpd = Routing.RouteTable.Routes.GetVirtualPath(Nothing, "element_maint", rvd)
vpdDeactivate = Routing.RouteTable.Routes.GetVirtualPath(Nothing, "element_deactivate", rvdDeactivate)
btnAction.addLink("Edit", vpd.VirtualPath, False)
If (ZenCommon.CurrentUser.secLevelId = cihCommonDef.FullSiteAdmin Or ZenCommon.CurrentUser.secLevelId = cihCommonDef.OrganizationAdmin) Then 'if SuperAdmin or Campus Admin
'Need Help here
btnAction.addLink("Deactivate", vpdDeactivate.VirtualPath, False)
End If
ZenCommon.AddCell(tr, ele.eleDescr, , , "200px")
tc = New TableCell
tc.Controls.Add(New LiteralControl(btnAction.buttonHTML))
tc.Style.Add("width", "50px")
tr.Cells.Add(tc)
Me.tblList.Rows.Add(tr)
Next
End Sub
Private Sub deactivateTag()
'Goto Database, flag 'tag' as inactive
End Sub
I want the btnAction.addLink("Deactivate") to call a function in my aspx.vb. The function will go mark the tag as inactive.
Right now the 'Edit" button (just above the 'Deactivate' button, will go to a new page to allow you to edit it. I get that. But is there a way to make it so when I click my 'Deactivate' button it will just call my deactivateTag()
In your codebehind you could change your method signature
Protected Sub deactivateTag(ByRef sender as Object, ByRef e as System.EventArgs) Handles btnDeactivate.Click
and in your markup
<asp:Button ID="btnDeactivate" onClick="deactivateTag" />
Or you can add a click event for the button and call your function from that event.
Protected Sub btnDeactivate_Click(ByRef sender as Object, ByRef e as System.EventArgs) Handles btnDeactivate.Click
deactivateTag()
End Sub
It depends on whether you'll need to call deactivateTag from other controls or not.
Related
I am trying to send the selected record of a gridview to the next page to populate the controls using Session with datatable.
I have added breakpoints and can see the datatable is populating but it does not seem to be sending over to the next page. Please Help.
Page one VB Code
Protected Sub grdClientlist_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles grdClientlist.SelectedIndexChanged
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(20) {New DataColumn("clientid"), New DataColumn("name"), New DataColumn("surname"), New DataColumn("type"), New DataColumn("status"), New DataColumn("assistant"), New DataColumn("companyname"), New DataColumn("telephoneno"), New DataColumn("mobileno"), New DataColumn("faxno"), New DataColumn("email"), New DataColumn("streetaddress"), New DataColumn("streetaddress2"), New DataColumn("streettown"), New DataColumn("streetcountry"), New DataColumn("streetpostalcode"), New DataColumn("postaladdress"), New DataColumn("postaladdress2"), New DataColumn("postaltown"), New DataColumn("postalcountry"), New DataColumn("pospostalcode")})
dt.Rows.Add(grdClientlist.SelectedRow.Cells(0).Text, grdClientlist.SelectedRow.Cells(1).Text, grdClientlist.SelectedRow.Cells(2).Text, grdClientlist.SelectedRow.Cells(3).Text, grdClientlist.SelectedRow.Cells(4).Text, grdClientlist.SelectedRow.Cells(5).Text, grdClientlist.SelectedRow.Cells(6).Text, grdClientlist.SelectedRow.Cells(7).Text, grdClientlist.SelectedRow.Cells(8).Text, grdClientlist.SelectedRow.Cells(9).Text, grdClientlist.SelectedRow.Cells(10).Text, grdClientlist.SelectedRow.Cells(11).Text, grdClientlist.SelectedRow.Cells(12).Text, grdClientlist.SelectedRow.Cells(13).Text, grdClientlist.SelectedRow.Cells(14).Text, grdClientlist.SelectedRow.Cells(15).Text, grdClientlist.SelectedRow.Cells(16).Text, grdClientlist.SelectedRow.Cells(17).Text, grdClientlist.SelectedRow.Cells(18).Text, grdClientlist.SelectedRow.Cells(19).Text, grdClientlist.SelectedRow.Cells(20).Text)
Session("client") = dt
Response.Redirect("ClientDetails.aspx")
End If
End Sub
Page 2 VB code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("dt") IsNot Nothing Then
Dim dtclient As DataTable = New DataTable()
dtclient = CType(Session("client"), DataTable)
txtClientNumber.Text = dtclient.Rows.Item("clientid").ToString
txtName.Text = dtclient.Rows.Item("name").ToString
txtSurname.Text = dtclient.Rows.Item("surname").ToString
cboClientType.Text = dtclient.Rows.Item("Type").ToString
cboClientStatus.Text = dtclient.Rows.Item("status").ToString
txtAssisstant.Text = dtclient.Rows.Item("assistant").ToString
txtCompanyName.Text = dtclient.Rows.Item("companyname").ToString
txtContactTel.Text = dtclient.Rows.Item("telephoneno").ToString
txtMobileNo.Text = dtclient.Rows.Item("mobileno").ToString
txtFaxNo.Text = dtclient.Rows.Item("faxno").ToString
txtEmailAddress.Text = dtclient.Rows.Item("email").ToString
txtStreetAddress.Text = dtclient.Rows.Item("streetaddress").ToString
txtStreetAddressL2.Text = dtclient.Rows.Item("streetaddress2").ToString
txtStreetAddressSuburb.Text = dtclient.Rows.Item("streettown").ToString
txtStreetCountry.Text = dtclient.Rows.Item("streetcountry").ToString
txtStreetPostalCode.Text = dtclient.Rows.Item("streetpostalcode").ToString
txtPostalAddress.Text = dtclient.Rows.Item("postaladdress").ToString
txtPostalAddressL2.Text = dtclient.Rows.Item("postaladdress2").ToString
txtPostalAddressSuburb.Text = dtclient.Rows.Item("postaltown").ToString
txtPostalCountry.Text = dtclient.Rows.Item("postalcountry").ToString
txtPostalPostalCode.Text = dtclient.Rows.Item("pospostalcode").ToString
End If
End Sub
I have tried indexing the row and also not indexing the row both same result.
If Session("dt") IsNot Nothing Then
Change this line to the following:
If Session("client") IsNot Nothing Then
The code for your second page is referencing the session variable by an incorrect name. In your first page you do:
Session("client") = dt
This assigns the DataTable dt to the session variable client. Top get back to this data from the second page (as has already been pointed out) you will need to reference Session("client"), which is what now holds your data. The original variable dt of type DataTable was destroyed as soon as the browser was done rendering the 1st page.
I have a page on the website that display a client details in text boxes.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not page.IsPostBack Then
Dim dh As New Datahandler
Dim CI As ClientInfomation = dh.GETClientInfomationWithClientID(Session("ClientID"))
txtClientID.Text = Session("ClientID")
txtCompany.Text = CI.Company
txtEmail.Text = CI.Email
txtPassword.text = CI.Password
dtSubcriptionEndDate.Text = CI.SubscriptionEndDate
txtContactName.Text = CI.ContactName
txtTelephoneNum.Text = CI.Telephone.ToString()
End If
The above code works,the code gets the client data from the database in the GETClientInfomationWithClientID(Session("ClientID")) and loads the data into a class, and from the class I load the data into the text boxes.
Here is where my problem starts. A user will now change his details in the text boxes and click the 'Save changes' button invoking the butSaveChanges_Click Event.
Protected Sub butSaveChanges_Click(sender As Object, e As EventArgs) Handles butSaveChanges.Click
Dim dh As New Datahandler
Dim CI As New ClientInfomation With {.ClientID = txtClientID.Text,
.Company = txtCompany.Text,
.ContactName = txtContactName.Text,
.Email = txtEmail.Text,
.Password = txtPassword.Text,
.SubscriptionEndDate = dtSubcriptionEndDate.Text,
.Telephone = txtTelephoneNum.Text}
If dh.SaveUserProfileChanegs(CI) = True Then
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Changes has been saved')", True)
Else
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Changes could not be saved')", True)
End If
End Sub
I just wanted to load the changed text values into the class, and load the class in the SaveUserProfileChanegs(CI) function that updates the new values in the database.
When the butSaveChanges_Click event is invoked I get a "(1) : error BC32022: 'Public Event Click As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event."
This one is REALLY driving me nuts. I've read, and tried, most of the workarounds but still it posts back!!
All the markup is generated dynamically from code-behind and inserted into a page that is part of a Master Page, from the init event.
There are a series of nested tabs, the tab content for the most part is data in a GridView. Each Gridview is set in it's own update panel. Every time a LinkButton in the GridView is clicked there is a full postback causing the tabs to reset (any button outside of the GridView and in the UpdatePanel doesn't cause a full postback.
LinkButtons are generated like this
Dim Select_Field As New CommandField
With Select_Field
.HeaderText = "View Transactions"
.SelectText = "View Transactions"
.ShowSelectButton = True
End With
GV.Columns.Add(Select_Field)
Registering with ToolKitScriptManager
Private Sub AssessmentsMain_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim vID As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID"))
Dim LB As LinkButton = CType(e.Row.Cells(4).Controls(0), LinkButton)
LB.ID = "AssMain_" & vID
AjaxControlToolkit.ToolkitScriptManager.GetCurrent(Me).RegisterAsyncPostBackControl(LB)
End If
Catch ex As Exception
Dim vError As New SendError
vError.MailError("840", PageName, ex)
ShowError()
End Try
End Sub
and the generated markup for one row is like this
<tr class="GridView" style="color:#333333;background-color:#F7F6F3;">
<td>10</td>
<td>Adam White</td>
<td>4224 Res Road</td>
<td align="right">$6,850.65</td>
<td>
<a id="ctl00_ContentPlaceHolder1_AssessmentsMainGV_ctl02_AssMain_10" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$AssessmentsMainGV','Select$0')" style="color:#333333;">View Transactions</a>
The GridView class
Public Class HAS_Gridview
Inherits GridView
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
CellPadding = 4
GridLines = WebControls.GridLines.None
ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
ClientIDMode = UI.ClientIDMode.AutoID
With MyBase.FooterStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Color.White
End With
RowStyle.BackColor = Drawing.ColorTranslator.FromHtml("#F7F6F3")
RowStyle.ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
PagerStyle.HorizontalAlign = WebControls.HorizontalAlign.Center
PagerStyle.ForeColor = Color.Black
PagerStyle.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
With MyBase.SelectedRowStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Drawing.ColorTranslator.FromHtml("#333333")
End With
With MyBase.HeaderStyle
.BackColor = Drawing.ColorTranslator.FromHtml("#E2DED6")
.Font.Bold = True
.ForeColor = Color.Black
.CssClass = "GridView"
End With
EditRowStyle.BackColor = Drawing.ColorTranslator.FromHtml("#999999")
With MyBase.AlternatingRowStyle
.BackColor = Color.White
.ForeColor = Drawing.ColorTranslator.FromHtml("#284775")
.CssClass = "GridView"
End With
With MyBase.RowStyle
.CssClass = "GridView"
End With
End Sub
End Class
Have you tried adding trigger programmatically instead of registering in AjaxControlToolkit:
Dim trigger As New AsyncPostBackTrigger()
trigger.ControlID = LB.ID
trigger.EventName = "Click"
MyUpdatePanel.Triggers.Add(trigger)
It looks like the postback is caused by href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$AssessmentsMainGV','Select$0')" in the generated markup for the anchor tag.
Try to define your own _doPostBack.
If you haven't checked post a and post b already, they offer a couple of ways to do that.
In the end the only way I could get this to work was
Create a class for a LinkButton Template
Public Class LinkButtonTemplate
Implements ITemplate
Private m_ColumnName As String
Event LinkButtonItem_Clicked(sender As LinkButton, e As EventArgs)
Public Property ColumnName() As String
Get
Return m_ColumnName
End Get
Set(ByVal value As String)
m_ColumnName = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal ColumnName As String)
Me.ColumnName = ColumnName
End Sub
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim LB As New LinkButton()
With LB
.ID = "LB_" & ColumnName
.Text = ColumnName
.OnClientClick = "LinkButtonClick(this);"
End With
container.Controls.Add(LB)
End Sub
End Class
Add this javascript so that it would post the ID to a hidden field and click a hidden button
Private Sub LoadLinkButtonClick()
Try
Dim SB As New StringBuilder
SB.Append("function LinkButtonClick(LinkButton){ ")
SB.Append("setTimeout(function() { ")
SB.Append("$get('" & GridViewLBClicked.ClientID & "').click(); ")
SB.Append(" }, 300); ")
SB.Append("var sendingID = LinkButton.id; ")
SB.Append("document.getElementById('" & HiddenField1.ClientID & "').value = sendingID; ")
SB.Append("} ")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "LoadLinkButton", SB.ToString, True)
Catch ex As Exception
Dim vError As New SendError
vError.MailError("1229", PageName, ex)
End Try
End Sub
On the RowDataBound event capture the ID we need and add it to the LinkButton ID (so now we know both the sending GridView and the selected row)
Private Sub AssessmentsMain_RowDataBound(sender As Object, e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim vID As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "ID"))
Dim LB As LinkButton = CType(e.Row.Cells(4).Controls(0), LinkButton)
LB.ID = "AssMain_" & vID
End If
Catch ex As Exception
Dim vError As New SendError
vError.MailError("840", PageName, ex)
ShowError()
End Try
End Sub
From the hidden button click we can recover all the data we need to make the async postback
Private Sub RaiseLinkButton_Click(sender As Object, e As EventArgs)
Try
Dim vFunction As New Functions
Dim vValue As String = HiddenField1.Value
Dim vSplit = vValue.Split("_")
Dim i As Integer = 0
For Count As Integer = 0 To vSplit.Length - 1
i += 1
Next
Dim DGName As String = vSplit(i - 2)
Select Case DGName
Case "AssMain"
Dim MV As MultiView = vFunction.FindControlRecursive(BodyMain, "AssessmentMultiView")
Dim GV As CustomControl.HAS_Gridview = vFunction.FindControlRecursive(BodyMain, "AssessmentDetailGV")
With GV
.DataSource = AssessmentsDetail_ReturnDataSet()
.DataBind()
.PageIndex = 0
End With
MV.ActiveViewIndex = 1
Dim vPanel As UpdatePanel = vFunction.FindControlRecursive(BodyMain, "AssessmentUpdatePanel")
vPanel.Update()
End Select
Catch ex As Exception
Dim vError As New SendError
vError.MailError("953", PageName, ex)
ShowError()
End Try
End Sub
I have a DropDownList iniwhich on page load it loads up all the data into it, however when the user wants to make a change to what text is displayed they just simply click on the dropdown and select the new one. My question is How do I make it so it saves the new text value that they choose? Here is what I have now:
Private Sub cboCure_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCure.SelectedIndexChanged
cboCure.AutoPostBack = True
Dim objXMLDoc As New System.Xml.XmlDocument
Dim objNodeList As System.Xml.XmlNodeList
Dim strXML As String = ""
Dim url As String = ""
MaterialStuff = New Message.Material
Dim code As String = cboCure.SelectedItem.Text
cboCure.Items.Clear()
If cboCure.Items.Count < 1 Then
strXML = Message.GetCureCodes
objXMLDoc.LoadXml(strXML)
objNodeList = objXMLDoc.GetElementsByTagName("Material_Cure")
cboCure.Items.Add("")
For Each childNode As System.Xml.XmlNode In objNodeList.Item(0).ChildNodes
cboCure.Items.Add(New System.Web.UI.WebControls.ListItem(childNode.SelectSingleNode("CureCodeLetter").InnerText,
childNode.SelectSingleNode("CureCode").InnerText))
Next
End If
cboCure.SelectedItem.Text = code
End Sub
I want the variable code to be the new text value that the user clicks but I can't seem to get it right, it keeps showing up as "" or the value that is originally displayed when the page loads.
EDIT:
Here is my Page_Load
If Not Page.IsPostBack Then
...code
else
cboCure_SelectedIndexChanged(sender, e )
end if
I am trying to add a button control to right of the previous/next of pager in asp.net gridview.
I've tried to work with examples on this site, but I need to keep the previous/next and put the button to the right of the bottom pager row.
At first I got a small (5px) it to show in the next cell, then after numerous other attempts, in now doesn't even appear.
How do I align a button to the right while keeping gridview generated next/previous buttons.
Thanks
Private Sub grdClientServiceType_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdClientServiceType.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Pager
'Dim space As New LiteralControl(" ")
'Dim span1 As New Label
'span1.Text = " "
'span1.Style("margin-left") = "50px"
'Dim butt As New Button
'butt.ID = "buttShowAvail"
'butt.BackColor = Drawing.Color.Purple
'butt.ForeColor = Drawing.Color.White
'butt.Font.Bold = True
'butt.ToolTip = "Click for a selection of times available."
'Dim table As Table = TryCast(e.Row.Cells(0).Controls(0), Table)
'Dim parentCell As TableCell = table.Rows(0).Cells(table.Rows(0).Cells.Count - 1)
'Dim w As Integer = parentCell.Width.Value
'parentCell.Controls.Add(space)
'parentCell.Controls.Add(butt)
Dim butt As New Button
butt.ID = "buttShowAvail"
butt.BackColor = Drawing.Color.Purple
butt.ForeColor = Drawing.Color.White
butt.Font.Bold = True
butt.ToolTip = "Click for a selection of times available."
AddHandler butt.Click, AddressOf buttShowAvail_Click
e.Row.Cells(0).ColumnSpan -= 1
Dim td As New TableCell
Dim span1 As New Label
span1.Text = "Show"
span1.Style("margin-left") = "10px"
td.Controls.Add(span1)
td.Controls.Add(butt)
Dim span2 As New Label
span2.Text = "rows per page"
td.Controls.Add(span2)
e.Row.Cells.Add(td)
End Select
End Sub
I finally figured it out, thanks to this site. I just need to change a few things to get this to work.
The solution is below...
Private Sub grdClientServiceType_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdClientServiceType.RowCreated
Select Case e.Row.RowType
Case DataControlRowType.Pager
Dim butt As New Button
butt.ID = "buttShowAvail"
butt.BackColor = Drawing.Color.Purple
butt.ForeColor = Drawing.Color.White
butt.Font.Bold = True
butt.ToolTip = "Click for a selection of times available."
butt.Width = "220"
butt.Height = "40"
butt.Text = "Show Availability"
butt.Font.Size = "11"
AddHandler butt.Click, AddressOf buttShowAvail_Click
e.Row.Cells(0).ColumnSpan -= 1
Dim td As New TableCell
td.Controls.Add(butt)
e.Row.Cells.Add(td)
End Select
End Sub