Dynamic Bootstrap Accordian loads in show - asp.net

I have a bootstrap accordion that is generated dynamically from code behind. It is loaded during page_init. Everything works except they are all set to open ('show') not closed ('hide').
If I take the generated markup and run it, it works fine so the html is OK. Any ideas?
Thanks
============== EDIT ============
This script resolves the problem
Private Sub SectionClose()
Try
Dim SB As New StringBuilder
SB.Append("$(document).ready(function(){")
SB.Append(" $('#accordion').accordion({ collapsible: true, active: false }); ")
SB.Append("$('.selector').accordion(); ")
SB.Append("}); ")
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ShowCollapse", SB.ToString, True)
Catch ex As Exception
Dim vError As New SendError
vError.MailError("214", PageName, ex)
End Try
End Sub
and it now works perfectly, but throws a Object doesn't support property or method 'accordion'
This is what the generated markup looks like
<div class="panel panel-default">
<div class="panel-heading">Current Board Members</div>
<!-- Start of Dynamic elements -->
<div id="MainContent_ContactBoardMembers" class="panel-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_1">John Doe - Treasurer</a></h4>
</div>
<div id="collapse_1" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_2">John Smith - President</a></h4>
</div>
<div id="collapse_2" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
<div class="panel-heading">
<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_3">Bill Mathews - Director at large</a></h4>
</div>
<div id="collapse_3" class="panel-collapse collapse">
<div class="panel-body"></div>
</div>
</div>
</div>
</div>
<!-- End of Dynamic elements -->
</div>
Edit - added to show how to create accordion from code behind
Dim i As Integer = 0
For Each Row As DataRow In DT.Rows
i = Row("Member_ID")
Dim MemberName As String = ""
MemberName += vFunction.ReturnText(Row("First_Name"))
MemberName += " " & vFunction.ReturnText(Row("Surname"))
MemberName += " - " & vFunction.ReturnText(Row("Position"))
Dim PanelHeading As New HtmlGenericControl("div")
With PanelHeading
.Attributes.Add("class", "panel-heading")
End With
Dim H4 As New HtmlGenericControl("h4")
With H4
.Attributes.Add("class", "panel-title")
End With
PanelHeading.Controls.Add(H4)
Dim aData As New HtmlGenericControl("a")
With aData
.Attributes.Add("class", "accordion-toggle collapsed")
.Attributes.Add("data-toggle", "collapse")
.Attributes.Add("data-parent", "#accordion")
.Attributes.Add("href", "#collapse_" & i)
' .Attributes.Add("data-target", "#collapse_" & i)
.InnerHtml = MemberName
End With
H4.Controls.Add(aData)

I noticed that the 'solution' (adding the script) didn't help and when I added jquery.ui to the page (for some reason it wasn't working in the bundle) the error went, but the issue was still there - I did notice that every time there was a javascript error the accordion worked, so I disabled one script at a time in the masterpage.
The NavBar is built dynamically and a script is loaded to change #media according to how large it is - once I changed .collapse to .navbar-collapse everything worked :-)

Related

First click modal doesn't open in .NET 5 Blazor server side

After loading a page, the very first click on any card doesn't open the modal window, but the next click and after, it will lunch the modal as it expected. I am not sure what caused this issue.
<div class="card-columns">
#foreach (var project in ProjectService.GetProjects())
{
<div class="card">
<div class="card-img" #onclick="(e => SelectProject(project.Id))" data-toggle="modal" data-target="#projectModal" style="background-image: url('#project.Image'); cursor: pointer;"></div>
<div class="card-body">
<h5 class="card-title">#project.Title</h5>
</div>
</div>
}
</div>
#if (selectedProject != null)
{
<div class="modal fade" id="projectModal" tabindex="-1" role="dialog" aria-labelledby="projectTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
...
C#:
#code {
Project selectedProject;
string selectedProjectId;
void SelectProject(string projectId)
{
selectedProjectId = projectId;
selectedProject = ProjectService.GetProjects().First(x => x.Id == projectId);
Console.WriteLine("hi");
}
The very first click, it reads the Console.WriteLine but doesn't show the modal, so I know selectedProject is not null and it suppose to show the modal. I tried to comment out all the javascript code I had and still have the issue. I also downloaded a new copy of bootstrap and replaced it into my project since I replaced some of the values (mostly fonts) by mistake and I found out that I should never edit the bootsrap. Still have the issue. There is also no console error in the browser.
So, this is not quite right, and I would say it's a lazy way to fix this issue because I still don't know what the root of the issue was, but I solved my problem by introducing a mouseover event to the card-img div:
<div class="card-img" #onclick="(e => SelectProject(project.Id))" #onmouseover="(e => start(project.Id))" data-toggle="modal">
C#
bool unlock;
void start(string projectId)
{
if (!unlock)
{
selectedProjectId = projectId;
selectedProject = ProjectService.GetProjects().First(x => x.Id == projectId);
unlock = true;
}
}
Now for the first time and only once when the mouse is going over a card, it will run the open modal but since it doesn't open for the first attempt, it basically does nothing but also make it interactable with the first click attempt.

ASP.NET Core 2.2 Razor Pages - textarea not binding correctly in Chrome or IE

I had finally got SignalR to send messages to a textarea successfully on my razor page, but for some reason the only browser that works is Microsoft Edge (using W10) Neither IE or Chrome displays the messages.
I've tried almost everything I can think of but nothing is fixing the issue.
I also find that an alert bar does not work in IE, but works in Chrome & Edge. Bit disappointing to find the number of issues that appear to stem between different browser platforms...
When testing between Edge & Chrome, joining the SignalR group using Chrome I know does work because I see the join message in Edge, so it seems we're dealing with simply a binding issue using Chrome, but as said all the below functionality using Edge is working Ok for me, very strange...
Razor Page:
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-6 col-sm-8">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<label asp-for="SystemMapping" class="control-label"></label>
<select asp-for="SystemMapping" class="form-control" asp-items="ViewBag.SystemMappingID" name="group-name" id="group-name">
<option>Select</option>
</select>
</div>
<div class="col">
#*Spare column here!*#
</div>
</div>
<div class="row" style="margin-top: 1em">
<div class="col">
<label for="exampleFormControlTextarea1">Inbound Events</label>
<textarea class="form-control" rows="20" id="inboundTextArea" oninput="countCharInbound(this)"></textarea>
</div>
</div>
<div class="row" style="margin-top: 1em">
<div class="col-md-auto col-sm-auto">
<button type="button" class="btn btn-secondary" onclick="eraseTextInbound();">
Clear Window
<i class="fas fa-broom"></i>
</button>
<div class="mb-2 mb-md-0"></div>
</div>
<div class="col-md-auto col-sm-auto">
<button type="button" class="btn btn-secondary" id="join-group">
Connect
<i class="fas fa-play"></i>
</button>
<div class="mb-2 mb-md-0"></div>
</div>
<div class="col-md-auto col-sm-auto">
<button type="button" class="btn btn-secondary" id="leave-group">
Disconnect
<i class="fas fa-pause"></i>
</button>
<div class="mb-2 mb-md-0"></div>
</div>
</div>
Razor Page js script:
<script>
// Clear Window button Inbound.
function eraseTextInbound() {
document.getElementById("inboundTextArea").value = "";
document.getElementById("inboundTextArea").innerHTML = "";
}
// Clear Window button Inbound.
function eraseTextOutbound() {
document.getElementById("outboundTextArea").value = "";
document.getElementById("outboundTextArea").innerHTML = "";
}
// When textarea reached x no. chars, clear text.
function countCharInbound(val) {
var len = val.value.length;
if (len >= 10000) {
document.getElementById("inboundTextArea").value = "";
document.getElementById("inboundTextArea").innerHTML = "";
}
}
// When textarea reached x no. chars, clear text.34
function countCharOutbound(val) {
var len = val.value.length;
if (len >= 10000) {
document.getElementById("outboundTextArea").value = "";
document.getElementById("outboundTextArea").innerHTML = "";
}
}
<script src="~/lib/signalr/dist/browser/signalr.js"></script>
<script src="~/js/systemEvents.js"></script>
SignalR js file script:
"use strict";
const connection = new
signalR.HubConnectionBuilder().withUrl("/messageHub").build();
// Function binds the Inbound messages received from
// SignalR to the inboundTextArea
connection.on("Send", function (message) {
var msg = message.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
var div = document.createElement("div");
// The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic).
//div.innerHTML = msg + "<hr/>"; // + "<hr/>" adds a line underneath each event message.
div.innerHTML = msg
document.getElementById("inboundTextArea").appendChild(div);
});
A partial solution here:
Changing the js script below has at least started showing the messages appear in Chrome as well as Edge, IE still not working though...
// Function binds the Inbound messages received from SignalR to the inboundTextArea.
connection.on("Send", (message) => {
var msg = message.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
$("#inboundTextArea").val($("#inboundTextArea").val() + '\n' + msg);
});

How to keep Bootstrap panel expanded/collapsed when changing view

I have 3 Bootstrap panels that expand/collapse when their headers are clicked.
However when changing to another route id (for example for :id=CarModel1 to id=CarModel2 with /cars/details/:id as route), I want to keep their state as was in the previous id after the user messes around with the panels, so that the user can compare the different details immediately when changing views.
How can I keep the panel state? Please, keep in mind I'm using ngRoute and not ui-Router.
Sample panel:
<div id="details">
<div class="panel-heading detailsPanel">
<a data-toggle="collapse" data-parent="#details" data-target="#collapseDetailsPanel">
<h4>Additional Details</h4>
</a>
</div>
<div id="collapseDetailsPanel" class="panel-collapse collapse">
<div class="panel-body">
<div>Lorem Ipsum</div>
</div>
</div>
</div>
Managed to do it by adapting a solution found here and using sessionStorage instead of $.cookie.
$("#details").on('shown.bs.collapse', function() {
var activeDetails = $("#details .in").attr('id');
sessionStorage.setItem('activeDetailsGroup', activeDetails);
});
$("#details").on('hidden.bs.collapse', function() {
sessionStorage.setItem('activeDetailsGroup', "inactive");
});
var lastDetails = sessionStorage.getItem('activeDetailsGroup');
if (lastDetails !== "inactive") {
//remove default collapse settings
$("#details .panel-collapse").removeClass('in');
//show the account_last visible group
$("#" + lastDetails).addClass("in");
}

Show available rooms through Status

We have an asp.net hotel room reservation project and I have difficulties in showing the rooms through its status. So if the user will book a room, it will reflect 'In' status in the table. And now, I tried to show the rooms which doesn't have 'In' Status and instead, show the rooms which have 'Out' status. Here is the code that I've been dying to fix:
<%
Dim MyConnNew As OdbcConnection
Dim MyCommNew As OdbcCommand
Dim MyDataReadNew As OdbcDataReader
Dim logic As Integer = 0
MyConnNew = New OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};Database=hotelsdb;Server=localhost;UID=root;")
MyConnNew.Open()
If MyConnNew.State = 0 Then
MyConnNew.Open()
End If
MyCommNew = New OdbcCommand("select * from hotelbookings where status ='" + "Out" + "'", MyConnNew)
MyDataReadNew = MyCommNew.ExecuteReader()
Dim roomParams As New List(Of Integer)()
While (MyDataReadNew.Read())
If MyDataReadNew.Item("roomid") <> 0 Then
roomParams.Add(MyDataReadNew.Item("roomid"))
logic = 1
End If
End While
Dim roomArray() As Integer = roomParams.ToArray()
If logic <> 0 Then
MyCommNew = New OdbcCommand("select * from hotelrooms", MyConnNew)
MyDataReadNew = MyCommNew.ExecuteReader()
Dim valid As Boolean
valid = False
While (MyDataReadNew.Read())
For i As Integer = 0 To roomArray.Length - 1
If MyDataReadNew.Item("roomid") = roomArray(i) Then
valid = True
End If
Next
If valid <> True Then
%>
<div class="col-xs-12 col-sm-4 col-md-4">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
<div class="grid wow zoomIn">
<figure class="effect-bubba">
<a href="Rooms.aspx">
<img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>
</a>
</figure>
<div class="text-left">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
<ul class="list-unstyled">
<li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
<li><b>Adults:</b> Up to 3 adult(s)</li>
<li><b>Children (0-12 yrs old):</b> Free</li>
<li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
<li><a class="btn btn-primary" href="insertreservation.aspx?room_id=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
</ul>
</div>
</div>
</div>
<nav id="myscroll" class="navbar navbar-default navbar-static top" role="navigation">
<h2>Select Available rooms</h2>
<div class="alert alert-info"><p><b>All rooms have:</b> 40-inch LED HDTV with cable channels• Media panel with HDMI, USB and A/V connectivity• Speaker Phone with iPod dock and FM Stereo• Executive Writing Desk• Complimentary Wi-Fi</p>
</div>
</nav>
<div data-spy="scroll" data-target="#myscroll" data-offset="0" style="height:500px;overflow:auto; position: relative;">
<div class="container">
<%While (MyDataReadNew.Read())%>
<div class="col-xs-12 col-sm-4 col-md-4">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomid"))%>"/>
<div class="grid wow zoomIn">
<figure class="effect-bubba">
<a href="Rooms.aspx">
<img src="assets/images/<%Response.Write(MyDataReadNew.Item("roomimage"))%>"/>
</a>
</figure>
<div class="text-left">
<input type="hidden" value="<%Response.Write(MyDataReadNew.Item("roomnumber"))%>" />
<ul class="list-unstyled">
<li><h2><%Response.Write(MyDataReadNew.Item("roomtype"))%> Room</h2></li>
<li><b>Adults:</b> Up to 3 adult(s)</li>
<li><b>Children (0-12 yrs old):</b> Free</li>
<li><b>Starting rate per night:</b> <%Response.Write(MyDataReadNew.Item("roomrate"))%> php</li>
<li><a class="btn btn-primary" href="insertreservation.aspx?roomid=<% Response.Write(MyDataReadNew.Item("roomid"))%>" >Reserve</a><br/></li>
</ul>
</div>
</div>
</div>
<%
End While
End If
MyDataReadNew.Close()
MyConnNew.Close()
%>
</div>
Hope you'll help with this :) Thanks
First of all, instead of two queries, you can write:
Select distinct hotelrooms.roomid, hotelrooms.roomimage, hotelrooms.roomtype --other fields here
from hotelbookings
left outer join hotelrooms on hotelrooms.roomid=hotelbookings.roomid
where hotelbookings.status ='Out'
or
select *
from hotelrooms
where roomid in --or 'not in'
(select hotelbookings.roomid
from hotelbookings
where hotelbookings.status ='Out')
Then we need tables structure.
I can't understand why you post
<div class="col-xs-12 col-sm-4 col-md-4">...</div>
maybe it's not related to your question.

resizing images using minimagick and carrier wave

I am trying to upload images to a blog using carrier wave. on the blog, I want all of the images to fit in the same size box, regardless of the size of the photo. I want all of them to be 450x253. Here is my code:
Uploader file for carrier wave:
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include Sprockets::Rails::Helper
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :resize_to_fill => [450, 253]
# Create different versions of files:
version :thumbnail do
process :resize_to_fill => [200, 112]
end
version :profile_size do
process :resize_to_fill => [450, 253]
end
version :full_size do
process :resize_to_fill => [568, 320]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
And my index.html.erb file:
<div class="row">
<% #articles.each do |article| %>
<div class="col-md-6">
<div class="well well-lg">
<p><%= image_tag(article.image.url) %>
<div class="body">
<div class="text-center">
<%= article.description %>
</div>
<div class="row">
<div class="col-xs-3">
<button class="btn btn-primary btn-lg" type="submit">Button</button>
</div>
<div class="col-xs-9">
<button class="btn btn-default btn-lg pull-right" type="submit">Button</button>
</div>
</div>
</div>
</div>
</div>
<% end %>
<div class="col-md-6 col-sm-6">
</div>
</div>
At this line:
<%= image_tag(article.image.url) %>
I have also tried:
<%= image_tag(article.image.profile_size.url) %>
since my uploader file says the profile_size should render 450x253, but that still doesn't work. With my current code, the size of the photo as it displays on the page is just the same size of whatever it is that I upload, it doesn't resize at all, for example:
I want them all to be the same size of the one on the left in the photo, but auto resized to that (the one in the photo is naturally that size), how can I do that? I already tried looking here: http://www.rubydoc.info/github/jnicklas/carrierwave/CarrierWave/MiniMagick
and here: Carrierwave - Resizing images to fixed width
thanks
Use resize_to_fit or resize_to_limit instead of resize_to_fill
process :resize_to_limit => [450, 253]
or
process :resize_to_fit => [450, 253]

Resources