LightSwitch hide delete button until record is selected - c#

I'm using Visual Studio 2013 and LightSwitch. I figured out how to create a delete record button and it works great. The only problem I have is on my main page where all records are shown.
When the page loads, The View & Edit buttons only appear once I select a record. the Add and Delete are visible all the time. The problem is, while the delete function works, it only works when a record is selected. So, if the page loads and you click delete it errors out. I would like to hide the delete button until a record is clicked on. By default the Edit and View buttons that Lightswitch creates do this, however since you have to write your own Delete function I have not figured out how to do this.
Here is an example of the C# i'm working with which works fine provided a record is selected..
myapp.BrowseGiftRegistries.DeleteRegistry_execute = function (screen) {
screen.GiftRegistries.deleteSelected();
return myapp.commitChanges().then(null, function fail(e) {
myapp.cancelChanges();
throw e;
});
};

In the delete button's _canExecute() method just put the following code:
myapp.MyScreen.DeleteButton_canExecute = function (screen) {
return screen.GiftRegistries.selectedItem != null;
};
You can also control whether the button is visible when disabled by checking or unchecking the "Hidden if disabled" checkbox in the properties for the selected button.

You should do it on client side using javascript(it seems that you have provided javascript code).
For example, if you have delete button named 'DeleteRegistry':
Add code below to your BrowseGiftRegistries.lsml.js
myapp.BrowseGiftRegistries.created = function (screen) {
screen.findContentItem('DeleteRegistry').isEnabled = false;
//screen.findContentItem('DeleteRegistry').isVisible = false;
};
// Function created by clicking List( Gift Registries)->properties window->
// ->Actions->Item tap->None->edit execute code
myapp.BrowseGiftRegistries.GiftRegistry_ItemTap_execute = function (screen) {
screen.findContentItem('DeleteRegistry').isEnabled = true;
//screen.findContentItem('DeleteRegistry').isVisible = true;
};
// Modification of your function
myapp.BrowseGiftRegistries.DeleteRegistry_execute = function (screen) {
screen.GiftRegistries.deleteSelected();
screen.findContentItem('DeleteRegistry').isEnabled = false;
//screen.findContentItem('DeleteRegistry').isVisible = false;
return myapp.commitChanges().then(null, function fail(e) {
myapp.cancelChanges();
throw e;
});
};
You can replace line containing isEnabled field with commented line containing isVisible field to reach result you need.

Related

Xamarin.İOS Hide Keyboard When Clicked Away

I have a login page in my app which uses UITextField element. I want to hide the keyboard when I click away from that TextField.
I tried using this code that I saw on a website in my ViewDidLoad function but it didn't work.
EntryTextField.ShouldReturn = (textField) =>
{
textField.ResignFirstResponder();
return true;
};
I solved the problem by adding these lines to ViewDidLoad():
View.UserInteractionEnabled = true;
UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(HideKyb);
tapGesture.NumberOfTapsRequired = 1;
View.AddGestureRecognizer(tapGesture);
and I added this line into the HideKyb function:
View.EndEditing(true);

How to create progress update control programatically in c# non visual web part in Sharepoint

How can I create progress update control programmatically in a c# non visual web part in Sharepoint?
I am using c# and the goal is to creates a text of "Loading..." inside the ProgressUpdate control that becomes visible while the update panel is loading more content and then disappears when content is loaded. If anyone can help that would be awesome. I tried the following, but no luck. A button triggers the update panel and the update works well, but when I try to add an update progress it gets added into the page, but it never appears when I click my button that triggers the update.
UpdatePanel up = new UpdatePanel();
up.UpdateMode = UpdatePanelUpdateMode.Always;
up.ID = "Panel1";
UpdateProgress upp1 = new UpdateProgress();
upp1.AssociatedUpdatePanelID = up.ID.ToString();
upp1.ID = "UpdateProgress1";
upp1.Controls.Add(new LiteralControl("<p>Loading...</p>"));
Controls.Add(upp1);
Alright so here is what I have found. If you make an Update Progress control outside an Update Panel, then it will fail to be able to listen to the trigger on the update panel when it fires. More can be read about that at the link below.
http://www.mostlydevelopers.com/blog/post/2008/08/23/Show-UpdateProgress-when-using-an-UpdatePanel-with-Triggers.aspx
So since I'm doing it this way, I had to use a javascript work around. I had to use the getInstance() method of the PageRequestManager object to get the instance of the PageRequestManager class. I then added the functions for the asynchronous request when it is initialized and ends. This will allow us to show our UpdateProgress control when an Asynchronous call begins and ends. (See Javascript Below)
//Function for postbackUpdateProgress
var prm = Sys.WebForms.PageRequestManager.getInstance();
var postBackElement;
function CancelAsyncPostBack() {
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack()) {
args.set_cancel(true);
}
//Get the element that asynchronous postback
postBackElement = args.get_postBackElement();
//check to see if any of the following controls activate sender request.
//search is used to search for the ID name in the string that sharepoint spits out
// as the ID.
var controlA = postBackElement.id.search("DropDownListType");
var controlB = postBackElement.id.search("UserProfileDropList");
var controlC = postBackElement.id.search("MoreNewsLinkButton");
var controlD = postBackElement.id.search("PreviousNewsLinkButton");
if (controlA != -1 || controlB != -1 || controlC != -1 || controlD != -1) {
$('*[id*=Panel1]:visible').hide();
//show UpdateProgress
$('*[id*=UpdateProgress1]').show();
}
}
//After async postback complete, then show panel again and hide UpdateProgress
function EndRequest(sender, args) {
$('*[id*=Panel1]').show();//use wild card in jquery to find Panel1 ID
$('*[id*=UpdateProgress1]:visible').hide();
}
Please note that I had to do a search() for the ID name because sharepoint puts a bunch of text before your ID name and javascript would otherwise not be able to find it by the text literal of the ID alone. A wild card approach with jquery is used to find the panel by using:
$('[id=Panel1]').show();//use wild card in jquery to find Panel1 ID
to show it.
and
$('[id=Panel1]:visible').hide();
to hide the update panel when the async call is initialized. You don't have to hide the update panel, but my particular implementation looks more aesthetically pleasing if I do.

How to unregister Page.ClientScript in C# Asp.net

I am registering java script to my Asp.net code behind file, which is working fine. Now, I have some update panels on the same page and problem is whenever there is any change in any of the update panel, this script is automatically getting called. Is there any way that I can stop this happening. I can't remove update panels from my page and this script is also a very essential part of the application. In this situation I am just calling a alert (rad alert with set time out functionality) when Save Button is clicked or an Update routine is called while I have few other buttons in update panels and whenver any of the button which is registered to the update panels clicked, the following script is called un-willingly. Anyone's help will really be appreciated.
following is my Page.ClientScript
string radalertscript = "<script language='javascript'> Sys.Application.add_load(function(sender, e) {var oWnd = radalert('dialogMessage', 400, 140, 'Saved');window.setTimeout(function () { oWnd.Close(); }, 3000);});</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
You can assign empty string to same key radalert to remove the script.
if(some_condition)
Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", "");
Edit: Based on comments, you can make it simple without using RegisterStartupScript
In code behind
btnSave.Attributes.Add("", "saveButtonFunction();");
In Javascript
<script language='javascript'>
Sys.Application.add_load(function(sender, e) {
if(btnSaveClicked){
var oWnd = radalert('dialogMessage', 400,140, 'Saved');
window.setTimeout(function () { oWnd.Close(); }, 3000);
btnSaveClicked = false;
}
});
btnSaveClicked = false;
function saveButtonFunction(){
btnSaveClicked = true;
};
</script>
Thank you very much for your answer Adil. I already have followed the same approach with little difference. I have taken JavaScript out from my code behind file and have registered Sys.Application.add_load event as follow
Sys.Application.add_load(DisplayRadAlertHandler);
function DisplayRadAlertHandler() {
var getMessage = document.getElementById('<%=radAlertDialogHidden.ClientID%>').value;
if (getMessage != "") {
document.getElementById('<%=radAlertDialogHidden.ClientID%>').value = "";
var oWnd = radalert(getMessage, 400, 140, 'Saved');
window.setTimeout(function () { oWnd.Close(); }, 3000);
}
}
Here I am setting my alert message in a hidden input field from code behind file and in the above event handler I am just checking if message is there than reset the hidden field and display the message. Your approach is also right and I have marked your answer but as I am displaying my message from multiple locations (Save button, Update routine etc.) so by assigning value to hidden input field and than resetting in above event handler looks more appropriate. Thanks once again for your help.

Disable clicking on tabPanel in TabContainer

I want to disable clicking and going from one tabPanel to another. Like here http://www.eldan.co.il/en/ the user can't select another step. I tried something like this
if (Tabs.ActiveTabIndex == 0)
{
Tabs.Tabs[1].Enabled = false;
}
but it hides the tab...
I found something that helped me.
...prevent switching to the tab on click depending on form validation
Returning false in the tabs select handler prevents the clicked tab from becoming selected.
$('#example').tabs({
select: function(event, ui) {
var isValid = ... // form validation returning true or false
return isValid;
}
});

Show/hide buttons based on a dropdown list

Currently I have an aspx page that contains a dropdown list and four buttons.
Based on the selection made in the dropdown list then a combination of the buttons are displayed.
I currently have this implemented so that when the user makes a selection I am using AutoPostBack and the selectedChanged server side event to determine which buttons to display and then set the Visible property of these buttons in this method.
Due to the fact that this posts back I don't think its a nice solution as the whole page is posting back. I would prefer to do this using JSON.
I made the following attempt but it doesn't seem to work:
$(document).ready(function () {
jQuery("#<%= MyDropdownList.ClientID %>").change(function () {
updateAvailableButtons(jQuery(this).val());
});
});
function updateAvailableButtons(selectedItemId) {
jQuery("h2").html("selectedItemId:" + selectedItemId);
jQuery.getJSON("MyPage.aspx/GetAvailableButtons?" + Id, function (data, textStatus) { debugger; });
}
Server side:
protected void GetAvailableButtons(int selectedItemId)
{
//based on the id here then then I show hide certain buttons.
button1.Visible = true;
button2.Visible = false;
button3.Visible = false;
button4.Visible = false;
}
I've never worked with JSON before so apologies if this is way off.
Similar task can be done using JavaScript. The problem is that you'll need to use a html control instead of an asp.net button control so that you can manipulate form the client side.

Categories