We have an EPiServer (forms) edit view with a number of tabs. The customer has requested that the tab which is #2 (called "alternative content"), should be automatically selected under certain conditions when the editors open the edit-page. We don't want to reorder the tabs. How can this be accomplished? We're running EPiServer 11.
Update:
I've tried to accomplish this using a Dojo-script. The result in EPiServer depends on how I set it up, which is kinda strange to me in this case. Here's the file
Web\modules\CMSDefaultTabSelector\module.config:
Here's how it's called in ModifyMetadata:
...and the script itself, CMSDefaultTabSelector.js, looks like this:
The result, depending on whether you send in EditLayoutContainer, Dialog, or skip it entirely (the way it should look), is as follows:
Result with EditLayoutContainer
Result with Dialog
The result as it should be
If I try to skip this parameter, I get the error "ctor is not a constructor". Other layout elements just render an empty tab, weirder errors, or you get other error messages. If I use require([...]), the function is called on every page reload, which is not what I want. I want it to only be called whenever the code from ModifyMetadata kicks in. Hope someone can help.
After fiddling around for quite a while, I finally found the magic code. Since other people might also wonder how this is done, here's how it was solved in the end (using Dojo):
define([
"dojo/_base/declare",
"epi/shell/layout/SimpleContainer"
],
function (
declare,
SimpleContainer
)
{
return declare([SimpleContainer], {
//constructor: function () {},
postCreate: function () { /* PostCreate fires too soon, and the tab strip is not completely rendered */ },
startup: function () {
// Use Jquery to select the tab we manually want to change to, and click it:
var tabElement = $("div.dijitContentPane span.tabLabel:contains('Additional content')");
if ($(tabElement).length) {
$(tabElement).trigger("click");
}
}
});
}
);
Related
Apologies for what is undoubtedly a newb question, but I have been unable to find a specific answer.
I have c#-integrated ASP.net Core project, with an SQL backend. I can run queries for individual entries just fine, but my problem is a far more mundane one.
I have a textbox, which I want to reload the page when the Enter key is pressed which the Text value appended to it. E.g. '~/GetPerson?name=' with the text the user's entered placed at the end.
This seems simple enough, and I'm probably missing the obvious, but I remain befuddled.
do you want this?
$("#textBox").on("keyup", function(e){
e.preventDefault();
if(e.keyCode===13){
//do call server or something
}
}
You can do something like this
$("#textBox").on("keyup", function(e){
e.preventDefault();
if(e.keyCode===13){
var name = (this).val();
window.location.href = '#Url.Action("GetPerson", "YourController")?name=' + name;
}
}
I dont know if it is even possible, but is there some way how to "end" page in Windows Phone 8 app?
My problem is that i am using one delegate (to know when is my xml downloaded) on multiple pages. It works fine, but when i open one page, she initialize herself, i go on other page (trough back button) and new page initialize herself too. Everything is fine, but the previous page is still listening to the delegate and it is really big problem. So i need to get the previous page (that closed) into a same state like she was not ever opened.
I will be thankful for any advice (maybe i am thinking in wrong way now, i dont know, maybe the page just have to be de-initialize).
PS: If its necessary i will post the code, but i think it is not. :)
Okey here is some code:
In class whis is downloading XML i have delegate like this:
public delegate void delDownloadCompleted();
public static event delDownloadCompleted eventDownloadCompleted;
This class is downloading few different xml files depends of constructor in run(int number) method.
After is download complete and all information from xml are saved in my local list i call delegateCompled. if (eventDownloadCompleted != null)
{
eventDownloadCompleted();
}
Then i have few different pages. All pages are used for display specific data from downloaded xml. So on this specific page I have method that is fired when "downloadClass" says it is complet.
XML_DynamicDataChat.delDownloadCompleted delegMetoda = new XML_DynamicDataChat.delDownloadCompleted(inicialiyaceListu);
XML_DynamicDataChat.eventDownloadCompleted += delegMetoda;
This is that "inicializaceListu" method:
private void inicialiyaceListu()
{
Dispatcher.BeginInvoke(() =>
{
model = new datka();
// object model is just model where i am saving all specific list of informations that i got from xml files.
chatList9 = model.getChat(1);
gui_listNovinky.ItemsSource = chatList9;
gui_loadingGrid.Visibility = Visibility.Collapsed;
});
}
All of these works fine, but when i go back (with back button) and open other specific page with other specific information from other downloaded xml, previous page is still listening for the delegate and inicialiyaceListu() method is still fired everytime i complete download of xml.
So i need to say previous page something like: "hey page, you are now closed! Can you shut the **** up and stop work?!?"
I think that specific delegate for each pages could solve this, but it is not correct programing way.
I solved it nice and easy. It is really simple solution. I just created bool variable and set it false when i go back. In inicializaceListu() i have condition if it is true. If it is true do that stuffs when false do nothing.
In my Xamarin Studio project on Mac, I am using MvvmCross version 3.0.13 from MvvmCross-Binaries, the XS-iOS-Mac Release assemblies, and I am trying to couple my CrossUI Dialog based View with a corresponding ViewModel. Specifically, I define the Root in my dialog view like this:
var bindings = this.CreateInlineBindingTarget<ViewModel>();
Root = new RootElement("New Connection") {
new Section {
new StringElement("Test")
.Bind(bindings, element => (object)element.SelectedCommand, vm => vm.TestConnection)
},
new Section {
new StringElement ("Add")
.Bind (bindings, element => element.Visible, vm => vm.CanAddConnection)
.Bind (bindings, element => (object)element.SelectedCommand, vm => vm.AddConnection)
}
};
In the ViewModel, CanAddConnection is set to true by the TestConnection command if test is successful.
When I run this (in the iOS Simulator) and open the dialog, the Test button is displayed and the Add button is hidden (as intended). When I click the button and the test is successful, the Add button is however not displayed, but instead I get this message in the application output:
How did this happen - CurrentAttachedCell is a child of a non-UITableView
Why is my Visible binding not working?
As far as I can tell, I have not made any code customizations upstream that would lead to this failure in the code (but I might be missing something).
If I bind CanAddConnection to another element property, for example Caption, the boolean value is properly updated in the view.
I think you are probably falling foul of an ios7 change which is addressed as part of https://github.com/MvvmCross/MvvmCross/issues/467
This fix will be included in 3.0.14 (hopefully in the next week) - in the meantime, the easiest workaround is probably to patch UpdateVisibility yourself in your own build - or to implement a custom StringElement
I have an application which writes HTML to a WebBrowser control in a .NET winforms application.
I want to detect somehow programatically if the Internet Settings have Javascript (or Active Scripting rather) disabled.
I'm guessing you need to use something like WMI to query the IE Security Settings.
EDIT #1: It's important I know if javascript is enabled prior to displaying the HTML so solutions which modify the DOM to display a warning or that use tags are not applicable in my particular case. In my case, if javascript isn't available i'll display content in a native RichTextBox instead and I also want to report whether JS is enabled back to the server application so I can tell the admin who sends alerts that 5% or 75% of users have JS enabled or not.
Thanks to #Kickaha's suggestion. Here's a simple method which checks the registry to see if it's set. Probably some cases where this could throw an exception so be sure to handle them.
const string DWORD_FOR_ACTIVE_SCRIPTING = "1400";
const string VALUE_FOR_DISABLED = "3";
const string VALUE_FOR_ENABLED = "0";
public static bool IsJavascriptEnabled( )
{
bool retVal = true;
//get the registry key for Zone 3(Internet Zone)
Microsoft.Win32.RegistryKey key = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3", true);
if (key != null)
{
Object value = key.GetValue(DWORD_FOR_ACTIVE_SCRIPTING, VALUE_FOR_ENABLED);
if( value.ToString().Equals(VALUE_FOR_DISABLED) )
{
retVal = false;
}
}
return retVal;
}
Note: in the interest of keep this code sample short (and because I only cared about the Internet Zone) - this method only checks the internet zone. You can modify the 3 at end of OpenSubKey line to change the zone.
If you are having troubles with popups popping up, i've included a solution for you, and if you want to disable/enable javascript on th client machine (or even just read/query if it is enabled/disabled) ive included that answer for you as well, here we go:
Which popup message do you want to disable? If it's the alert message, try this, obviously resolving the window or frame object to your particular needs, I’ve just assumed top-level document, but if you need an iframe you can access it using window.frames(0). for the first frame and so on... (re the JavaScript part)... here is some code, assuming WB is your webbrowser control...
WB.Document.parentWindow.execScript "window.alert = function () { };", "JScript"
You must run the above code only after the entire page is done loading, i understand this is very difficult to do (and a full-proof version hasn't been published yet) however I have been doing it (full proof) for some time now, and you can gather hints on how to do this accurately if you read some of my previous answers labelled "webbrowser" and "webbrowser-control", but getting back to the question at hand, if you want to cancel the .confirm JavaScript message, just replace window.alert with window.confirm (of course, qualifying your window. object with the correct object to reach the document hierarchy you are working with). You can also disable the .print method with the above technique and the new IE9 .prompt method as well.
If you want to disable JavaScript entirely, you can use the registry to do this, and you must make the registry change before the webbrowser control loads into memory, and every time you change it (on & off) you must reload the webbrowser control out and into memory (or just restart your application).
The registry key is \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\ - the keyname is 1400 and the value to disable it is 3, and to enable it is 0.
Of course, because there are 5 zones under the Zones key, you need to either change it for the active zone or for all zones to be sure. However, you really don't need to do this if all you want to do is supress js dialog popup messages.
Let me know how you go, and if I can help further.
Here is a suggestion - Encode the warning into your webpage as default. Create a javascript that runs on page load which removes that element. The warning will be there when ever javascript is not allowed to run.
It's a long while since I coded client side HTML javascript to interact with the DOM so I may be a little out of date. i.e. you will need to fix details, but I hope I get the general idea across.
<script>
document.getElemntByID("noJavascriptWarning").innerHTML="";
</script>
and in your HTML body
<DIV id="noJavascriptWarning" name="noJavaScriptWarning">Please enable Javascript</DIV>
Am unable to understand why Cannot the below javascript code is not called from code behind
I have a simple javascript block like this
function callsCox(res) {
alert(res);
}
From my code behind :
....
string res="COX23";
string script = String.Format("callsCox({0})", res);
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Cox",script,true);
Am I missing anything? There aren't any exceptions or errors.
Page.ClientScript.RegisterStartupScript looks OK to me (might have missed something). Things to try
Add apostrophes to the call - it's coming through as an object. Try as a string
string script = String.Format("callsCox('{0}')", res);
Is the string script Page.ClientScript.RegisterStartupScript being called after an update panel partial postback. That could effect it
I have know functions not been found if they are in the same page. Try moving to an external js file. Don't asked me why this has resolved issues but it has a couple of times in the past for me.
Just for debug purposes take the function out of the equation all together, Try to get the alert working like this. It will at least isolate the problem if it does work
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Cox","alert('Does this work?')",true);
View the source of the page. Is the function even written into the page (or alert from point 4). It should be. If you put a breakpoint on the this.Page.ClientScript.RegisterStartupScript method is it being hit? Seems like it might not be.
Apologies for not giving you a 'hey this is the solution' type of answer. I've had stuff like this in the past and I've found it a matter of stripping things down until the problem has been isolated. Someone else may be able to spot an immediate problem of course. Good luck.
This works for me:
public static void ShowAlert(Page page, String message)
{
String Output;
Output = String.Format("alert('{0}');",message);
page.ClientScript.RegisterStartupScript(page.GetType(), "Key", Output, true);
}