I am struggling to render my DataSet contents into DIV tags with column names as headers.
I am trying to get it within a structure like so:
<div class="dataset">
<div class="dsheader">
<div class="dscell"><h6>Staff Name</h6></div>
<div class="dscell"><h6>Accrued Hours</h6></div>
<div class="dscell"><h6>Date Accrued</h6></div>
</div>
<div class="dsrow">
<div class="dscell"><p>1</p></div>
<div class="dscell"><p>2</p></div>
<div class="dscell"><p>3</p></div>
</div>
<div class="clearfix"/>
</div>
I have no idea how to start so I started the easy way and rendered the data into a table:
Dim r As DataRow
Dim dvCont As New HtmlGenericControl
Dim dvHead As New HtmlGenericControl
Dim dvRow As New HtmlGenericControl
Dim dvCell As HtmlGenericControl
For i As Integer = 0 To DataTable.Rows.Count - 1
Dim myRow As New HtmlTableRow
Dim divrow As New HtmlGenericControl
Dim divcell As New HtmlGenericControl
Dim StaffMemberCell As New HtmlTableCell
Dim LieuTypeCell As New HtmlTableCell
Dim LieuDateCell As New HtmlTableCell
Dim LieuDetailsCell As New HtmlTableCell
StaffMemberCell.InnerHtml = DataTable.Rows(i).Item("staff_member").ToString
myRow.Cells.Add(StaffMemberCell)
LieuTypeCell.InnerHtml = DataTable.Rows(i).Item("lieu_type").ToString
myRow.Cells.Add(LieuTypeCell)
LieuDateCell.InnerHtml = DataTable.Rows(i).Item("lieu_date").ToString
myRow.Cells.Add(LieuDateCell)
LieuDetailsCell.InnerHtml = DataTable.Rows(i).Item("lieu_details").ToString
myRow.Cells.Add(LieuDetailsCell)
lieuTable.Rows.Add(myRow)
Next
Where do I go from here?
I know to add runat="server" to DIV tags on the ASPX page.
<div id="dvContainer" class="dataset" runat="server">
<div id="dvContHeader" class="dsheader" runat="server">
<div id="dvContCell" class="dscell" runat="server"><h6>Header</h6></div>
<div id="Div1" class="dscell" runat="server"><h6>Header</h6></div>
<div id="Div2" class="dscell" runat="server"><h6>Header</h6></div>
</div>
<div id="dvRow" class="dsrow" runat="server"><p>data1</p></div>
<div id="dvContCell" class="dsrow" runat="server"><p>data1</p></div>
<div id="Div4" class="dsrow" runat="server"><p>data1</p></div>
<div id="Div5" class="dsrow" runat="server"><p>data1</p></div>
</div>
</div>
Another issue I have is do I have to explicitly state the div within the ASPX doc? See below. I see an issue with using the ID tags multiple times.
I achieved the result I was looking for by using a repeater.
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="dsDataSet">
<div class="dsheader">
<div class="dscell"><h6>Staff Name</h6></div>
<div class="dscell"><h6>Accrued Hours</h6></div>
<div class="dscell"><h6>Date Accrued</h6></div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="dsrow">
<div class="dscell"><p><%# Eval("Staff_member")%></p></div>
<div class="dscell"><p><%# Eval("Num_Hours")%></p></div>
<div class="dscell"><p><%# Format(Eval("Lieu_Date"), "dd-MM-yyyy")%></p></div>
</div>
</ItemTemplate>
<FooterTemplate>
<div class="clearfix"/>
</div>
</FooterTemplate>
</asp:Repeater>
Related
I'm trying to get the "valor" that is inside the site div from Poloniex to put inside a Label every 1 second using Timer after load site completely.
My Completely Code:
https://pastebin.com/QrcuWnxf
Div:
<div class="info">valor</div>
I have found that on the page there are several "info" classes...
This code worked, but it brought another result than expected ...
Dim theElementCollection As HtmlElementCollection
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Div")
For Each curElement As HtmlElement In theElementCollection
If curElement.OuterHtml.Contains("info") Then
Variable1 = (curElement.GetAttribute("InnerText"))
End If
Next
Label1.Text = Variable1
The result was the value of this Div that also has the "info" class.
<div class="msg"><div class="info">OMG/BTC and OMG/ETH OmiseGO markets added</div>
Change the second try:
For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
If Element.GetAttribute("className") = "lastPrice" Then
For Each Element1 As HtmlElement In Element.GetElementsByTagName("div")
If Element1.GetAttribute("className") = "info" Then
Dim Variable1 as String = Element1.InnerText
End If
Next
End If
Next
Yes, you have to use className for class attribute.
This code is verified against the following HTML: This also have more than 1 info class.
<html>
<body>
<div class="firstPrice">
<div class="name">First Price</div>
<div class="info">11650.00</div>
</div>
<div class="lastPrice">
<div class="name">Last Price</div>
<div class="info">11650.00</div>
</div>
</body>
</html>
I have an aspx page with a sidebar on the left.
The sidebar shows from one to many tasks grouped by date.
I want to show a modal popup passing an ID when user clicks a task.
The sidebar is something like this:
01/09/2016
Go to the dentist
Meet with Anna
02/09/2016
blabla
03/09/2016
bla1
bla2
bla3
etc.
On page load I declare variables and query my database with this:
Dim elementoLi As String = "<li><h2><i class=""fa fa-cog fa-fw""></i>XXX</h2>YYY</li>"
Dim htmlTitle As String = "<div class=""title"">
<h1>XXX</h1>
</div><div class=""content""><ul>YYY</ul></div><br/>"
Dim htmlContent As String = ""
Dim htmlChiamateaperte As String = ""
Dim htmlfinale As String = ""
Dim chiamateAperte = From statoRic In
dbVulcano.StatoRic.Where(Function(s) s.RFStato >= 11 And s.RFStato <= 13 And s.Attuale = 1 And s.RFTecnico = rfTecnico)
From richiesta In
dbVulcano.Richieste.Where(Function(r) r.IDRic = statoRic.RFRic).DefaultIfEmpty()
From cliente In
dbVulcano.Clienti.Where(Function(c) c.IDCliente = richiesta.RFCliente).DefaultIfEmpty()
Select statoRic.RFRic, statoRic.RFStato, statoRic.Attuale, richiesta.Descr, cliente.RagSociale, statoRic.DataAss, statoRic.Data, dataf = If(statoRic.DataAss.HasValue, statoRic.DataAss, statoRic.Data)
Order By dataf Descending
Then I cycle to create the sidebar structure:
For Each item In chiamateAperte
Dim data1 = Format(item.dataf, "dd/MM/yyyy")
If htmlChiamateaperte.Contains(data1) = False Then
htmlChiamateaperte = htmlChiamateaperte & Replace(htmlTitle, "XXX", data1)
htmlContent = ""
End If
For Each item2 In chiamateAperte
Dim data2 = Format(item2.dataf, "dd/MM/yyyy")
If data2 = data1 Then
Dim rags, desc As String
desc = UppercaseFirstLetter(item2.Descr)
rags = item2.RagSociale
htmlContent = htmlContent & Replace(Replace(elementoLi, "XXX", rags), "YYY", desc)
End If
Next
htmlChiamateaperte = Replace(htmlChiamateaperte, "YYY", htmlContent)
Next
divChiamateAperte.InnerHtml = "<h1>CHIAMATE APERTE</h1><br /><br />" & htmlChiamateaperte
Basically I dinamically create a string that at the end is passed as html code. What I need is to add links in the "elementoLi" var so that, once the user click on the link, it opens a modal popup (and passes along an ID). How can I do that? Doesn't matter if I have to change all the code to create the structure. Thanks
EDIT 1:
This is the structure I need:
<div class="panel" runat="server" id="divChiamateAperte" autopostback="true">
<h1>CHIAMATE APERTE</h1><br /><br />
<div class="title"><h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 1</h2> Descrizione 1</li>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 2</h2> Descrizione 2</li>
</ul>
</div>
<br />
<div class="title"><h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 1</h2> Descrizione 1</li>
<li><h2><i class="fa fa-cog fa-fw"></i> RAGIONE SOCIALE 2</h2> Descrizione 2</li>
</ul>
</div>
</div>
EDIT 2:
I made this example using the structure above and the repeater, but the problem I see to obtain the above (where the block made by div title to div content can be 1 to infinite) is that I need to repeat the repeater result from 1 to X (where x is the data read from db).
<%# Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Repeater Example</title>
<script runat="server">
Sub Page_Load(Sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values As New ArrayList()
values.Add("Apple")
values.Add("Orange")
values.Add("Pear")
values.Add("Banana")
values.Add("Grape")
' Set the DataSource of the Repeater.
Repeater1.DataSource = values
Repeater1.DataBind()
End If
End Sub
</script>
</head>
<body>
<h3>Repeater Example</h3>
<form id="form1" runat="server">
<b>Repeater1:</b>
<br />
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<div class="title">
<h1>dd/mm/yyyy</h1>
</div>
<div class="content">
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<h2><i class="fa fa-cog fa-fw"></i><%# Container.DataItem %></h2>
Descrizione 1</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</div>
</FooterTemplate>
</asp:Repeater>
<br />
</form>
</body>
</html>
First of all, it is not recommended to use
Dim html as String = ""
html += .....
html += .....
this consume a lot of RAM on the server
Second, you may want to use the Repeater control if you are using .NET webform. Read more on the why on: http://blog.zay-dev.com/net-web-form-implementation-strategy-3-the-controls/
Example (.ASPX):
<asp:Repeater runat="server" ID="RepeaterCode">
<ItemTemplate>
<div>
<h1><asp:Literal runat="server" ID="LiteralHeader"/></h1>
<span class="<asp:Literal runat='server' ID='LiteralSpanClass'/>">
<asp:Literal runat="server" ID="LiteralSpanContent"/>
</span>
</div>
</ItemTemplate>
</asp:Repeater>
.ASPX.VB:
Protected Sub Page_Load(sender as Object, e as EventArgs) Handles Me.Load
RepeaterCode.DataSource = Source
RepeaterCode.DataBind()
End Sub
Protected Sub RepeaterCode_ItemDataBound(sender as Object, e as RepeaterItemEventArgs) Handles RepeaterCode.ItemDataBound
If (TypeOf e.Item Is RepeaterItem) Then
Dim LiteralHeader as Literal = e.Item.FindControl("LiteralHeader")
If (LiteralHeader IsNot Nothing) Then LiteralHeader.Text = "Header"
End If
End Sub
Edit 1 -
ASPX:
<div class="panel" id="divChiamateAperte">
<h1>CHIAMATE APERTE</h1>
<br /><br />
<asp:Repeater runat="server" ID="RepeaterGroups" OnItemDataBound="RepeaterGroups_ItemDataBound">
<ItemTemplate>
<div class="title">
<h1>
<asp:Literal runat="server" ID="LiteralHeader"/>
</h1>
</div>
<div class="content">
<ul>
<asp:Repeater runat="server" ID="RepeaterItems" OnItemDataBound="RepeaterItems_ItemDataBound">
<ItemTemplate>
<li>
<h2>
<i class="fa fa-cog fa-fw"><i>
<asp:Literal runat="server ID="LiteralItemText"/>
</h2>
<a href="#" onclick="ShowModal($(this).attr("data-id"))" data-id="<asp:Literal runat='server' ID='LiteralID'/>">
<asp:Literal runat="server" ID="LiteralAnchorText"/>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
.ASPX.VB:
Protected Sub Page_Load(sender as Object, e as EventArgs) Handles Me.Load
If (Not Me.IsPostBack) Then
Dim dt as DataTable = Model.GetSideBarGroups()
RepeaterGroups.DataSource = dt
RepeaterGroups.DataBind()
End If
End Sub
Protected Sub RepeaterGroups_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
If (TypeOf e.Item Is RepeaterItem AndAlso e.Item.DataItem IsNot Nothing) Then
Dim dr as DataRow = e.Item.DataItem
Dim GroupID as Integer = If(IsDBNull(dr("GroupID")), -1, Integer.Parse(dr("GroupID").ToString()))
Dim GroupDate as DateTime = If(IsDBNull(dr("GroupDate")), DateTime.Today, DateTime.Parse(dr("GroupDate").ToString()))
Dim dt as DataTable = Model.GetSideBarItems(GroupID)
Dim LiteralHeader as Literal = e.Item.FindControl("LiteralHeader")
Dim RepeaterItems as Repeater = e.Item.FindControl("RepeaterItems")
If (LiteralHeader IsNot Nothing) Then LiteralHeader.Text = GroupDate.ToString("dd/mm/yyyy")
If (RepeaterItems IsNot Nothing) Then
RepeaterItems.DataSource = dt
RepeaterItems.DataBind()
End If
End If
End Sub
Protected Sub RepeaterItems_ItemDataBound(Sender As Object, e As RepeaterItemEventArgs)
' To-Do
End Sub
I am a bit stumped on this one. I have some html that has an image in it, followed by some text. But I need to rearrange the html so the image comes first - so image, then h3 tag, then the text.
EDIT: The cod below does not actually remove the style attribute. I thought it was working till i looked more closely at the html source. So I need help with stripping the style attribute given
<p>
<img alt="" src="../../../../images/PeterDoocy5.jpg" style="width: 608px; height: 316px;" /></p>
So far I have managed to use the HAP to strip out the style attributes of the images in the page using:
<Extension()> Public Function RemoveStyleAttributes(input As String)
Dim cleint As New WebClient
Dim html As New HtmlDocument
html.LoadHtml(input)
Dim elementsWithStyleAttribute = html.DocumentNode.SelectNodes("//#img")
If elementsWithStyleAttribute IsNot Nothing Then
For Each element In elementsWithStyleAttribute
element.Attributes("style").Remove()
Next
End If
Return input
End Function
But I am at a loss as to how then pull put the image and put in front of the H3 tag.
HTML:
<div class="col-md-6">
<div class="item">
<div class="content galleryItem">
<h3>
DOJ court docs in Abu Khattallah case dispel Obama Admin narrative about the anti-Islam video
</h3>
<p>
<img alt="" class="img-responsive" src="../../../../images/AbuKhattala.jpg" />
</p>
<p>
But it was an awful, disgusting video.....
</p>
</div>
</div>
</div>
The Extension method now:
<Extension()> Public Function RemoveStyleAttributes(html As HtmlDocument)
Dim divs = html.DocumentNode.SelectNodes("//div[#class='content galleryItem']")
For Each div As HtmlNode In divs
'get <img> and remove its style attribute'
Dim img = div.SelectSingleNode("./p/img[#style]")
img.Attributes("style").Remove()
'remove <h3> and <p>text here</p>'
Dim h3 = div.SelectSingleNode("./h3")
h3.Remove()
Dim text = div.SelectSingleNode("./p[not(img)]")
text.Remove()
'add <h3> and <p>text here</p> to the parent again in desired order'
div.AppendChild(h3)
div.AppendChild(text)
Next
Return html.DocumentNode.OuterHtml.ToString
End Function
Attempting to use it as #Html.Raw(item.PostSummary.RemoveStyleAttributes)
You can try this way :
<Extension()> Public Function RemoveStyleAttributes(input As String)
Dim cleint As New WebClient
Dim html As New HtmlDocument
html.LoadHtml(input)
For Each div As HtmlNode In divs
'get <img> and remove its style attribute'
Dim img = div.SelectSingleNode("./p/img[#style]")
img.Attributes("style").Remove()
'remove <h3> and <p>text here</p>'
Dim h3 = div.SelectSingleNode("./h3")
h3.Remove()
Dim text = div.SelectSingleNode("./p[not(img)]")
text.Remove()
'add <h3> and <p>text here</p> to the parent again in desired order'
div.AppendChild(h3)
div.AppendChild(text)
Next
Return html.DocumentNode.OuterHtml.ToString
End Function
Output (formatted. given input html as posted in this question) :
<div class="col-md-6">
<div class="item">
<div class="content galleryItem">
<p>
<img alt="" class="img-responsive" src="../../../../images/AbuKhatta
la.jpg">
</p>
<h3>
DOJ court docs in Abu Khattallah case dispel Obama Admin narrative a
bout the anti-Islam video
</h3>
<p>
But it was an awful, disgusting video.....
</p>
</div>
</div>
</div>
</div>
<p id="content-profile-view">
<h3 class="content-profile-title" id="content-profile-title-profile">
Member Profile </h3>
<div class="content-profile-display" id="content-profile-display-profile">
<fieldset class="fieldgroup group-membership"><legend>Membership</legend><div class="field field-type-text field-field-membertype">
<div class="field-items">
<div class="field-item odd">
<div class="field-label-inline-first">
Member Type: </div>
Fellow </div>
</div>
</div>
In the HTML above I want to return Member Type: Fellow. My code below will get me Member Type: BUT I can't seem to get the Fellow Part. See my code below in vba.
Dim collection As MSHTML.IHTMLElementCollection
Dim element As MSHTML.HTMLInputElement, subElement As MSHTML.HTMLInputElement
Dim a As String
Dim b As String
Set collection = Doc.getElementsByTagName("div")
For Each element In collection
If element.className = "field-label-inline-first" Then
a = element.innerText
Debug.Print a
End If
Next element
to get the second piece of data, you'll need to look for divs with the class 'field-item', because fellow is included in that overall div, not the filed-label-inline-first div
I've reformatted the content below to make it more obvious what is going on here.
<div class="field-item odd">
<div class="field-label-inline-first">Member Type: </div>
Fellow
</div>
I have a bit of a difficult problem which I can't seem to find out how to solve.
Basically, I have a couple tables on my database which, identify, by client, which divs IDs the client has access to, by using the tab
So I have a table which identifies the divs by their ID, by using the table index:
id | id_div
0 | D0
1 | D1
(and so on..)
And then another one which has only the clients ID and the divs (identified by the "id" field) he has access to:
client_id | div_id
29 | 0
29 | 1
(and so on..)
Then I'm cross referencing which divs should be visible and which should not.
The problem is I am getting the divs id as a string and in order to be able to tell in code-behind to set the visibility to false I need to reference the div in itself..
A sample:
<dx:TabPage Name="tabServico" Text="<%$ Resources:InterfaceGenerica, lblServico %>">
<ContentCollection>
<dx:ContentControl>
<div class="conteudo_pagina_tab">
<asp:HiddenField ID="hidID" runat="server" Value="0" EnableViewState="true" />
<asp:HiddenField ID="hidIdCliente" runat="server" Value="0" EnableViewState="true"/>
<div id="D0" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litClientes" runat="server" Text="<%$ Resources:InterfaceGenerica, lblCliente %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboClientes" runat="server" HelpText="" ValueField="id_cliente" TextField="nome_completo" SelectedValue="" Width="100%" AutoPostBack="true"></dx:ASPxComboBox>
</div>
</div>
<clear></clear>
<div id="D1" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litTipoOperacao" runat="server" Text="<%$ Resources:InterfaceGenerica, lblOperacao %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboTipoOperacao" runat="server" Width="100%" HelpText="" ValueField="id_operacoes" TextField="nome" SelectedValue="" AutoPostBack="true">
</dx:ASPxComboBox>
</div>
</div>
<clear></clear>
<div id="D2" runat="server">
<div class="cols coluna1">
<asp:Literal ID="litTipoServs" runat="server" Text="<%$ Resources:InterfaceGenerica, lblTipoServico %>"></asp:Literal>
</div>
<div class="cols coluna2-4">
<dx:ASPxComboBox ID="cboTipoServs" runat="server" HelpText="" ValueField="id_tipo_servs" TextField="nome" SelectedValue="" AutoPostBack="true" Width="100%"></dx:ASPxComboBox>
</div>
</div>
<div id="D3" runat="server">
<div class="cols coluna5">
<asp:Literal ID="litSubTipoServs" runat="server" Text="<%$ Resources:InterfaceGenerica, lblSubtipoServico %>"></asp:Literal>
</div>
<div class="cols coluna6-8">
<dx:ASPxComboBox ID="cboSubTipoServs" runat="server" HelpText="" ValueField="id_tipo_subtipos" TextField="nome" SelectedValue=""></dx:ASPxComboBox>
</div>
</div>
And in code behind I have:
Dim cross As New Hashtable()
Dim divsCliente() As String
Dim lstDivs As List(Of campos_agd_form)
lstDivs = campos_agd_form_mapper.CarregarDivs()
If lstDivs IsNot Nothing Then
For Each i In lstDivs
cross.Add(i.id, i.id_div)
Next
End If
Dim lstDivsCliente As List(Of clientes_campos_agd)
lstDivsCliente = clientes_campos_agd_mapper.CarregarCamposCliente(guser.id)
If lstDivsCliente IsNot Nothing Then
divsCliente = (lstDivsCliente.Item(0).id_campos_enum).Split(",")
End If
'Dim divsCliente() As Integer = Convert.ToInt32((lstDivsCliente.id_divs).Split(","))
For Each item In cross
For Each i In divsCliente
If item.Key = Convert.ToInt32(i) Then
Dim div As System.Web.UI.HtmlControls.HtmlGenericControl
div = TryCast(item.Value, System.Web.UI.HtmlControls.HtmlGenericControl)
div.Visible = False
End If
Next
Next
As I was already expecting I can't convert a string into a HtmlObject so what I need to do is to find an object by it's id (the string), without having to go through the parent-object (basically, search the whole document, like one would do with javascript with a getElementById)
How can this be accomplished?
The framework I'm using is .NET 4.0
I Recommend the following approach.
You need to know which information to show to each user, so you might want to store this in session for example (Global.asax):
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fetch from DB
Session("Rights") = {"MyID1", "MyID3"}
End Sub
Then create a base user control that checks from the session if it's id is in the list of the rights the user has. If not, the control will automatically hide it self:
Imports System.Linq
Public MustInherit Class MyBaseControl
Inherits System.Web.UI.UserControl
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
If Page.IsPostBack Then Return
Dim rights As String() = CType(Session("Rights"), String())
If Not rights.Any((Function(s) s = Me.ID)) Then Me.Visible = False
End Sub
End Class
Then create x number of content controls that inherit from this base control. These controls can have totally different content, but consider making as few as possible, since your D0, D1 etc seem to have almost same content. So just customize the control to handle different texts and values:
Public Class MyControl1
Inherits MyBaseControl
End Class
Then on the page you will have as many of these controls as needed:
<div>
<uc1:MyControl1 ID="MyID1" runat="server" />
<uc2:MyControl2 ID="MyID2" runat="server" />
<uc3:MyControl3 ID="MyID3" runat="server" />
</div>
Hope this helps.
So, I ended up doing things a little differently.
Basically I'm using a ClientScriptManager, and constructing an array with the elements to hide. (Which is then passed to the client side).
So the function now looks like this:
Private Sub ManipulaFormCliente()
Dim cross As New Hashtable()
Dim divsCliente() As String = New String() {}
Dim aux() As String = New String() {}
Dim cs As ClientScriptManager = Page.ClientScript
Dim lstDivs As List(Of campos_agd_form)
lstDivs = campos_agd_form_mapper.CarregarDivs()
If lstDivs IsNot Nothing Then
For Each i In lstDivs
cross.Add(i.id, i.id_div)
Next
End If
Dim lstDivsCliente As List(Of clientes_campos_agd)
lstDivsCliente = clientes_campos_agd_mapper.CarregarCamposCliente(" id_cliente = " & Convert.ToInt32(hidIdCliente.Value))
If lstDivsCliente IsNot Nothing Then
If lstDivsCliente.Count <> 0 Then
divsCliente = (lstDivsCliente.Item(0).id_campos_enum).Split(",")
End If
End If
For Each item In cross
For Each i In divsCliente
If item.Key = Convert.ToInt32(i) Then
cs.RegisterArrayDeclaration("divsCliente", "'" & item.Value & "'")
End If
Next
Next
End Sub
Then, on the client side I made a function which runs once the window has loaded, and uses the array constructed on code-behind to apply a css "display: none" on the divs whose IDs get passed on the array.
The code is the following:
window.onload = function hideFields() {
if (divsCliente.length > 0) {
for (var i = 0; i < divsCliente.length; i++) {
document.getElementById(divsCliente[i]).style.display = 'none';
}
}
}
This implements the behaviour desired: Whenever there's a postback (and respective load) this function is run, hiding the required divs/fields.
As a final touch, I had to add the 'clientidmode = "static"' attribute to the divs, in order to get the getElementById() function to work properly (according to the data in the DB)
I hope this helps anyone in need of a similar solution.