Why aren't runAs=Server controls on this page accessible from VB? - vb.net

Okay, this one is just perplexing and annoying …. I’m hoping someone out there can help.
I have several aspx pages with server-side controls manipulated in the Visual Basic backing code; the vast majority work as advertised without any problems at all. Then there's this guy:
In the aspx page:
<%# Page Title="COVID-19 Staff Information" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="COVID-19.aspx.vb" Inherits="COVID_19_COVID_19" %>
…
<asp:Content ID="COVID_Main" ContentPlaceHolderID="MainContent" Runat="Server">
<div id="updateMeFromVB" runat="server"></div>
…
In the Visual Basic:
Partial Class COVID_19_COVID_19
…
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
…
updateMeFromVB.InnerHtml = html
End Sub
On compilation, I get:
… COVID-19.aspx.vb(28,0): error BC30451: 'updateMeFromVB' is not declared. It may be inaccessible due to its protection level.
HOWEVER, if I comment out that one line from Page_Load, it compiles great, put a breakpoint in the Page_Load subroutine, and when the breakpoint is hit do a “Quick Watch” on “updateMeFromVB” and there it is, all instantiated and happy.
I’ve been round and round this mulberry bush. If I uncomment the updateMeFromVB.InnerHtml = html line, I get a compilation error – comment it out, and I can see the variable in the debugger.
Any clues?????
I’ve got other pages in the same solution where this is working just fine … over on one of those:
ASPX:
<%# Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="CareLinkIndex.aspx.vb" Inherits="CareLink_Index" %>
…
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<!--#include file="GeneratedLinkList.htmlTxt" -->
<div id="AdminOnlyDiv" runat="server" style="text-align: left">
…
VB:
Public Sub Page_Load(sender As Object, e As EventArgs)
AdminOnlyDiv.Visible = IsMaintainer()
End Sub
Works great.

Okay, so the answer makes less sense than the question. But I found a similar issue (#6217414) and the answer there was to rename the page.
Can't hurt, right?
So COVID-19.aspx is now CovidEmpPage.aspx ... and everything works like it should.
That absolutely should not have worked, and is definitely indicative of a bug in Visual Studio.

Related

ASP .NET call button click from Javascript or JQuery

I have a button in a page:
<asp:Button ID="BtnOpening" runat="server" Text="Locale" OnClientClick="TipologiaMenuClick('1')" AutoPostBack="False" CausesValidation="False" />
Clicking this button calls a javascript:
function TipologiaMenuClick(TipoMenu)
{
...
some things
...
var BtnRefreshMenuList = document.getElementById('MainContent_BtnRefreshMenuList')
if (BtnRefreshMenuList != null)
{
alert('1');
BtnRefreshMenuList.click();
alert('2');
}
}
BtnRefreshMenuList is a button calling a procedure in the backend.
With FireFox I see the first alert, then the backend is called (I have a breackpoint there).
With Edge or Chrome, I see the first alert, the backend is NOT called, and I see the second alert.
I tried with JQuery
$("#MainContent_BtnRefreshMenuList").click();
but nothing changes: all ok with FireFox, nothings works with Edge or Chrome.
Any suggestion?
Edit 28/07 10:08:
I have new informations:
I tried with a double call:
$("#MainContent_BtnRefreshMenuList").click();
setTimeout(function () { $("#MainContent_BtnRefreshMenuList").click() }, 50);
The first call works with FireFox, I found the second call as a suggestion online, and SHOULD work for other browsers.
In different PCs and different virtual machines I see different behaviours.
In a virtual machine Windows 7 the page works with Firefox, Edge, Chrome, in another virrtual machine with Windows 7 the page works only with Firefox.
In my physical PC Windows 10 the page works with all browsers.
I removed all internet data, cookies included, but nothing changes.
This thing is driving me CRAZY.
Edit 28/07 11:12:
browser compatibility is bettere with
setTimeout(function () { $("#MainContent_BtnRefreshMenuList").click() }, 10);
and even better with
setTimeout(function () { $("#MainContent_BtnRefreshMenuList").click() }, 5);
It seems related with the timeout: with 5 milliseconds the page works well with a lot of browsers, from Windows, Iphone, Android.
I have reproduced your situation as simply as I can. Clicking the button does not prevent the 2nd alert from showing, but once you dismiss the 2nd alert it will do the postback, providing you don't lose focus on Chrome for any reason. If you lose focus then the postback won't happen, and the alerts are auto-dismissed. This must be a Chromium thing.
Initial state:
After clicking: "Trigger back end post through JS ..."
After dismissing the alert
Finally
HOWEVER, if I minimise Chrome before dismissing either alert, the postback will never happen.
Here is the ASPX code
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="ClickButtonTest.aspx.vb" Inherits="Scrap.ClickButtonTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script>
function backEndPostBack() {
var button = document.getElementById("btn_BackEndPost")
if (typeof button !== 'undefined') {
alert("Going to click the button.");
button.click();
button.value = "I've been clicked";
alert("Should never reach this alert because of the postback.")
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
Trigger back end post through JS (will click the button below)<br />
<br />
<asp:Button ID="btn_BackEndPost" runat="server" ClientIDMode="Static" Text="I've not been clicked" />
<asp:Literal ID="lit_PostbackStatus" runat="server" >No postback has happened yet...</asp:Literal>
</div>
</form>
</body>
</html>
Here is the VB.NET code
Public Class ClickButtonTest
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub btn_BackEndPost_Click(sender As Object, e As EventArgs) Handles btn_BackEndPost.Click
lit_PostbackStatus.Text = "btn_BackEndPost_Click was fired on the server..."
End Sub
End Class

Re-using a stimulus action elsewhere on the page?

I am wiring up a slack clone (html/css) and have it so that the reference drawer opens/closes when I click on the x. I am wanting to also open/close it from the navigation area and thought I could just take the same link_to and call it from a different part of the page.
But when I do that, if I'm calling it from within a different target, I get an error
Error invoking action "click->navigation#toggle_reference_drawer"
Error: Missing target element "navigation.referenceDrawer"
How can I use code inside a data-target to trigger a different data-target?
i.e. what I'm trying to get working is
--navigation partial (link_to doesn't work) --
<div data-navigation-target="storyNavLinks">
<div class ="story">
<%= link_to "[x]", "#", data: { action: "click->navigation#hide_reference_drawer" } %>
</div>
</div>
-- application partial (link_to works) --
<div data-navigation-target="referenceDrawer">
<div class='reference box'>
<%= link_to "[x]", "#", data: { action: "click->navigation#hide_reference_drawer" } %>
</div>
</div>
Not sure where I'm going wrong.. I figured as long as the target being referenced is unique and on the page it shouldn't matter where it's being called from?
You have to make sure your data-controller attribute is on an element that wraps both targets. If that is not possible you can always include the controller twice but the targets will only be scoped to each instance so you will need to add them twice as well.

Upgrade TinyMCE to 5, one form does not show the editor on a textarea control

I'm using Bootstrap 4.5, and have several forms all using the exact same setup to call TinyMCE 5, but one form (the most complex of course) is not showing it. I can find nothing wrong, or anything different between the way the textarea control is created. The code to load TinyMCE is being loaded in a PHP program and is therefore identical in all cases. This is the code being streamed out:
<!-- Jquery -- required for interactive parts of bootstrap and other code to function -->
<script src="../../Awards/jscode/jquery.min.js"></script>
<!-- Bootstrap core JavaScript, popper.js required for tooltips and such -->
<script src="../../Awards/jscode/popper.min.js"></script>
<script src="../../Awards/jscode/bootstrap.js"></script>
<!-- TinyMCE -->
<script src="../../Awards/jscode/tinymce/tinymce.min.js"></script>
<script language="JavaScript">
// TinyMCE, set for all textarea controls, with specific toolbar items, no menubar, etc.:
tinymce.init(
{
selector: 'textarea',
menubar: false,
branding: false,
plugins: 'code lists',
toolbar: 'undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent | code',
lists_indent_on_tab: true,
content_css: '<?php echo $Award_html_RootPath; ?>css/AwardList.css'
}); // end of TinyMCE code
</script>
This works for other forms with the same code being streamed out for each. I am stumped as to why this one form doesn't display TinyMCE. The textarea control in question is:
<div class="form-group">
<textarea name="Notes" id="Notes"
class="form-control"
style="height: 250px;"></textarea>
</div> <!-- / form-group -->
Thanks in advance for any suggestions that might point me to where the problem lies. There is a lot of JavaScript for this form but it all seems to work, it's just the TinyMCE code that doesn't want to load ... it displays as a standard textarea, no overlay for TinyMCE.
Okay, so now I feel really sheepish. I was outputting at the top of the page some styles before the header information was loaded properly, so TinyMCE wasn't seeing "standards" mode, which includes the first line of the HTML file needing to be:
<!DOCTYPE HTML>
Moved the script tags to below the code that streams the header into the page so that, among other things, the doctype tag above is the first line, and all is well. Sorry for wasting anyone's time on this.

DNN 7 module moves every other module up

I'm running a local install of DNN in a development capacity. I have a "testimonials" module that I want to use. The problem I get is that when I drag into a pane it causes all modules above it to "shift" up to a point where they go behind a content slider I have. Tried various CSS methods to fix it but I can't seem to find the bug. Has anyone else experienced the issue before??
Also tried contacting the owner but his last activity was in 2012.
thanks
<%# Control Language="vb" AutoEventWireup="false" Codebehind="Testimonials.ascx.vb" Inherits="Ovionx.DNN.Testimonials.Testimonials" %>
<asp:Panel ID="pnlTestimonials" runat="server">
<div id="rotating_homepage_text">
<asp:Repeater ID="rptTestimonials" runat="server">
<ItemTemplate>
<div>
<%# FormatTestimonial(Container.DataItem) %>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:Panel>
<script type="text/javascript">
// <![CDATA[
var currentTallest = 0;
var offsetPadding = 0;
$("#rotating_homepage_text")
<% If ShowPager Then %>
.before('<div id="rotating_homepage_text_nav">')
<% End If %>
.cycle({
fx: 'turnUp',
speed: <%= TransitionSpeed.ToString %>,
speedIn: 100,
speedOut: 100,
pager: '#rotating_homepage_text_nav'
})
.children().each(function(){
if ($(this).height() > currentTallest) {
currentTallest = $(this).height();
}
});
offsetPadding = $("#rotating_homepage_text").offset().top - $("#<%=pnlTestimonials.ClientID%>").offset().top;
$("#<%=pnlTestimonials.ClientID%>").css('height', (currentTallest + offsetPadding + 30) + 'px');
// ]]>
</script>
One thing you might try is switching to the LAYOUT mode on the page and see if that allows you to position the modules on the page.
Layout mode "hides" the content itself, so you can work with the module/containers to move things around, where in Edit/View mode that can sometimes be more difficult to do.
You might ultimately need to modify the Content Slider module if it is positioning things wrong in HTML, that or customize your SKIN so that the slider is in a different Pane than all other modules.

Dont understand how views work in ASP.NET

I'm trying to understand ASP.NET MVC4.
Within HomeController I have code that seems to call a view ...
public ViewResult RsvpForm()
{
return View();
}
And here is the view....
#model PartyInvites.Models.GuestResponse
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>RsvpForm</title>
</head>
<body>
<div>
#using (Html.BeginForm()) {
#Html.ValidationSummary()
<p>Your name: #Html.TextBoxFor(x => x.Name) </p>
<p>Your email: #Html.TextBoxFor(x => x.Email)</p>
<input type="submit" value="Submit RSVP" />
}
</div>
</body>
</html>
What I dont understand is...
How come the view has access to data when I the call view with empty parameters?
And what this is for: #model PartyInvites.Models.GuestResponse
What is going on with x => x.Name. I believe this is an anonymous function, but I dont understand the need for it. And I do not see where x comes from (it doesnt appear in the code above. Is it a global or something?).
To help with answers, I have done lots of PHP and web stuff and I have grasped most of C# and Razor, so I am assuming I am just being thick or this is something special for ASP
Thanks.
x => x.Name is an anonymous function - it's never executed.
In fact, the Html helper casts it as an Expression<Func<TModel, TProperty>>. This is similar to anonymous functions in PHP or passing functions around in JavaScript (Well, Func is, Expression wraps that and allows access to the execution tree of the function - basically tons of metadata about the function itself).
Once in the html helper, TextBoxFor, there's a ton of extra processing and comparison of the expression tree against the model metadata. Attributes get factored in and all that is used to build up the HTML (like [Required] or [Scaffold])
Your controller doesn't pass in data, but the view declares a strong model.
In the view, #model PartyInvites.Models.GuestResponse does not mean any data is actually passed in. It merely declares the view as strongly typed and makes the model metadata available to Intellisense and the view compiler. The Controller/View relationship is a whole lot more complicated than just a simple function call, unlike most PHP MVC frameworks (or basic PHP includes). The data the controller passes in gets wrapped up into the Page and ViewData with all the metadata and controller context and more.