Trying to show or hide a DIV with vb.net code - html

Following example stated in
How can i do an if statement inside a repeater
I'm trying to show or hide a div in html page that works with vb.net code, but no success.
<div runat="server" visible='<%# Container.DataItem.cod_dni = "10211721")%>' >
Hello
</div>
Got error ID:
BC30944
Syntax error in cast operator; two arguments separated by comma are required.
Also I tried
<div runat="server" visible='<%# Container.DataItem("cod_dni") = "10211721")%>' >
Hello
</div>
and got same error ID.

You probably just need to cast the Container.DataItem.. Assuming cod_dni is a string, try this:
<div runat="server" visible='<%# CStr(Container.DataItem("cod_dni")) = "10211721"%>' >
Hello
</div>
Also,
there's an extra ) in your statement at the end, so I took it out.

Try this:
visible='<%# IIf(Eval("cod_dni").ToString() = "10211721",true,false) %>'

Related

ngx-color Color Picker in Angular, not able to set width

I'm using the ngx-color Color Picker:
https://www.npmjs.com/package/ngx-color#material
This is where I call the Color Picker and where I want to set the width
<div>
<div class="flex-title">
<h3 class='h3-btn'>Background Color</h3>
<button mat-icon-button (click)="openColorPicker()">
<mat-icon>color_lens</mat-icon>
</button>
</div>
<jhi-bring-color [value]="this.color"></jhi-bring-color>
<color-sketch *ngIf="isColorPickerOpen" color="#fff" width="200px"
(onChange)="changeOfColor($event)"></color-sketch>
</div>
Somehow it works and the Color Picker gets shown correctly:
Still I get the following error in the console:
Type 'string' is not assignable to type 'number'.
<color-sketch *ngIf="isColorPickerOpen" color="#fff" width=200px (onChange)="changeOfColor($event)">
I've tried these cases too: width = "200", width = 200
Any idea why this error is shown, even though it is working?
Thank you for the help in advance!
From the error message, I guess that you have to write it like this:
<color-sketch *ngIf="isColorPickerOpen" color="#fff" [width]="200"
(onChange)="changeOfColor($event)"></color-sketch>
Without the brackets the value of the parameter will transferred as string inside the component.
After some time now I just took another color picker that looks similar.
https://www.npmjs.com/package/ngx-color-picker
It works fine and is simpler.
<div>
<h3 class='h3-btn'>Background Color</h3>
<input [(colorPicker)]="color" [style.background]="color"/>
</div>
Based on this " width - String | Number, Pixel value for picker width ", you should write like this :
<color-sketch *ngIf="isColorPickerOpen" [color]="#fff" [width]="'200px'"
(onChange)="changeOfColor($event)"></color-sketch>

HTML data update for XML column with new value in SQL Server

I have some experience in XQuery to update the XML data. I have tried to use the same logic for the HTML data in SQL Server.
But not working as expected.
For example I have a XML column Value (actually HTML data) as below.
Declare #template xml = '<div>
<div id="divHeader">Congratulation<div id="Salutation">ravi</div></div><br/>
<div>From now you are a part of the Company<div id="cmpnyUserDetails"></div></div><br/>
<div id="clickSection">Please Click Here to Access Your New Features</div>
</div>'
and I would like change the html value od the div with ID "Salutation" to "New Value" and Append the href value to a valid link using the XQuery.
SET #template.modify('replace value of (//div[id=("Salutation")]/text())[1] with "New Value"')
SELECT #template AS data
But it's not working.
Can someone please suggest to me how to make it happen?
Thanks a ton in advance,
Ravi.
You were close. Notice the #id vs. your id
Example
SET #template.modify('replace value of (//div[#id=("Salutation")]/text())[1] with "New Value"')
select #template as data
Returns
<div>
<div id="divHeader">Congratulation<div id="Salutation">New Value</div></div>
<br />
<div>From now you are a part of the Company<div id="cmpnyUserDetails" /></div>
<br />
<div id="clickSection">Please Click Here to Access Your New Features</div>
</div>

how to deal with ng-src with invalid url in ng-repeat

I would like to show the picture of a user if there is a user in my object list (profileList), and default/error as defaultProfile.png when no user is found ({{item.userProfile}} is null)
I have searched for similar approaches such as
angularjs: ng-src equivalent for background-image:url(…)
and
empty ng-src doesn't update image
My approach to this problem is:
<div ng-repeat="item in profileList">
<div>
<img src='assets/img/defaultProfile.png' data-ng-src="http://example.com/{{item.userProfile}}.jpg" onerror="this.src='assets/img/defaultProfile.png'" />
</div>
<div>
I am able to show error photo however I am still getting error 500,
GET http://example.com/.jpg 500 (INTERNAL SERVER ERROR)
How to avoid getting http://example.com//.jpg?
Thanks a lot
Your current issue is ng-src is still compiled and evaluated to an invalid url when userProfile is undefined.
A simple solution is to use ternary and check for userProfile before deciding with url should be rendered:
<img ng-src="{{ item.userProfile ? 'http://example.com/' + item.userProfile + '.jpg'}} : 'assets/img/defaultProfile.png'" />
It will guarantee that you will always fetch the default image unless item.userProfile is available.
One approach is to use ng-if and ng-hide:
<div ng-repeat="item in profileList">
<div>
<img ng-if="item.userProfile"
data-ng-src="http://example.com/{{item.userProfile}}.jpg" />
<img ng-hide="item.userProfile"
src="assets/img/defaultProfile.png" />
</div>
<div>
When item.userProfile exists, show the ng-src and hide the default otherwise vice versa.
It works.
ng-show
will run no matter {{item.userProfile}} is null or not.
By changing it to
ng-if
Below code is working:
<div ng-repeat="item in profileList">
<div>
<img ng-if="item.userProfile"
data-ng-src="http://example.com/{{item.userProfile}}.jpg" />
<img ng-if="item.userProfile == null"
src="assets/img/defaultProfile.png" />
</div>
note that my profileList is:
$scope.profileList = {userProfile = null}
Thanks a lot

get element id with vb

I have the following code in an aspx page:
<div id="objectList" style="overflow: auto; width:100px; display:block;
position:absolute;top:0px;left:0px;z-index:100;">
<div id="object8" class="object" title="">
<br>object8</div>
<div id="object2" class="objectSelect" title="">
<br>object2</div>
</div>
I am attempting to find the ID of the object that is selected, in this case object2. I am trying to do it in the codebehind with vb.net but I'm not sure how. Any help would be appreciated.
Add runat="server" to all of the <div> elements you wish to find out if they are selected or not, like this:
<div id="object8" class="object" title="" runat="server">
<div id="object2" class="objectSelect" title="" runat="server">
Now in code-behind you can loop through all of the <div> elements in the page and check the class attribute value, like this:
For Each item As Control In Me.Controls
' We have to look at all HtmlGenericControl, because
' there is no .NET control type for DIV
Dim theDiv As System.Web.UI.HtmlControls.HtmlGenericControl = TryCast(item, System.Web.UI.HtmlControls.HtmlGenericControl)
' Make sure the cast worked before we try to use the DIV
If theDiv IsNot Nothing Then
' Is the class name equal to objectSelect?
If theDiv.Attributes("class") = "objectSelect" Then
' Yes, this DIV is selected, do something here
End If
End If
Next

Load html from returned string

I have the string and its returning function in the code-behind:
string xmlContents = "<ul><li>Installation<br /><ul><li>Startup</li><li>Getting there</li><li>Steps</li>" +
"<li>Pictures</li></ul></li><li>Usage<br /><ul><li>Tilbud pane</li><li>Report pane</li>" +
"</ul></li></ul>";
public String returnXml()
{
return xmlContents;
}
Then I call it in the aspx file:
<div id="treeviewMenu">
<%returnXml(); %>
</div>
When I simply write the html code (of the list) directly in the div - it's ok. But by passing the string - it doesn't work.
What am I doing wrong and how to fix it ?
Note: = sign whithout ; sign
Replace with this code:
<div id="treeviewMenu">
<%=returnXml() %>
</div
You can easily assign html to div by making div server accessible by adding runat="server"
HTML
<div id="treeviewMenu" runat="server"></div>
In code behind
treeviewMenu.InnerHTML = xmlContents;