I have been stuck for a couple days now and I have tried a few things in regards to pre-populating my checkbox. I have a view model and 2 functions called "callServiceget" which calls a webservice to get the value of my checkbox field (true or false) and "retVendor" which updates the value of the checkbox.
if the value of the checkbox in the database is true, I want it to be checked when i load the page, unfortunately, I am unable to accomplish this. Any help or advice is much appreciated. Thanks in advance.
<input class="input" type="checkbox" data-bind="checked: vendor_inventory" />
<script type="text/javascript">
function VendorViewModel() {
var self = this;
self.vendor_inventory = ko.observable("");
self.callServiceGet = function (id) {
vendors.get("accounting", 2, id, self.retVendor);
}
self.retVendor = function (results) {
self.vendor_inventory(results.inventory);
}
//self.vendor_inventory.subscribe(function (value) {
// alert(value);
//},self);
}
</script>
<script type="text/javascript">
var id = 122;
vm = new VendorViewModel();
vm.callServiceGet(id);
ko.applyBindings(vm);
</script>
Related
I want to show DetailTemplate for Kendo UI Grid by conditions.
I tried the following cases:
detailTemplate: '#if(ResultDate!= null){ =kendo.template($("#detailRequestTemplate").html()) }#',
and
detailTemplate: function (e) {
if (ResultDate != null)
{
return kendo.template($("#detailRequestTemplate").html());
}
},
both of them don't work correctly
Try putting this logic inside the template instead.
<div id="grid"></div>
<script type="text/x-kendo-template" id="detailRequestTemplate">
#if(ResultDate !== null) {#
//...your template html
#}#
</script>
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
detailTemplate: kendo.template($("#detailRequestTemplate").html()),
});
});
</script>
For a more complete example, look at this dojo.
Also take a look at Telerik's Templates Overview documentation.
I found a solution for it:
dataBound: function (e) {
var items = e.sender.items();
items.each(function () {
var row = $(this);
var dataItem = e.sender.dataItem(row);
if (ResultDate !== null) {
row.find(".k-hierarchy-cell").html("");
}
})
},
This code removes an "arrow", if condition is false
I have some code to set the value of a hidden field so I can access it in the code behind but the value is always empty in the code behind. The value for the effectiveDate is being set but I doesn't look like the hidden field property Value is being set.
<input id="appEffectiveDate" type="text" />
<label id="effectiveDateLabel" for="appEffectiveDate">App Effective Date</label>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<asp:HiddenField ID="appEffectiveDateToSetForUserRole" runat="server" Value="" Visible="false" />
<script>
$(function () {
var SelectedDates = {};
$('#appEffectiveDate').datepicker({
beforeShowDay: function (date) {
var Highlight = SelectedDates[date];
if (Highlight) {
return [true, "Highlighted", Highlight];
}
else {
return [true, '', ''];
}
}
});
$("#effectiveDateLabel").hide();
$("#appEffectiveDate").hide();
$('input[value="85"]').click(function () {
if($(this).is(':checked'))
{
$("#effectiveDateLabel").show();
$("#appEffectiveDate").show();
}
});
$("#appEffectiveDate").change(function () {
var effectiveDate = $("#appEffectiveDate").val();
$(":asp(appEffectiveDateToSetForUserRole)").prop('value', effectiveDate);
});
});
</script>
In the code behind the value is empty for the hidden field:
if (!string.IsNullOrEmpty(appEffectiveDateToSetForUserRole.Value))
{
// this is never called because .Value is empty
}
If Visible is set to false, the control will not be rendered by ASP.NET in the markup at all, which means that jQuery won't be able to find it because it doesn't exist. Just remove the visible=false part. It'll stay hidden.
I have an <asp:menu/> control and a hidden field.Now i am using jQuery to change value of hidden field.
Code is:-
$(function() {
$(".primaryStaticMenu tr,td").each(function(index) {
$(this).click(function() {
if ($(this).attr("title") != "undefined"
&& $(this).attr("title").length > 0) {
document.getElementById('ctl00_Hidden_Master_Location').value = $(this).attr("title");
alert(document.getElementById('ctl00_Hidden_Master_Location').value);
//return false;
}
});
});
});
Server side code to get updated value is:-
string Get_cng_value = Hidden_Master_Location.Value;
But Hidden_Master_Location.Value shows null every time.
can any one tell me how to get updated value of hidden field from code behind.
Let say your hidden field is as..
<asp:HiddenField ID="Hidden_Master_Location" runat="server" />
you can get the value of hidden filed in jquery as
var locationValue= $("#<%= Hidden_Master_Location.ClientID %>").val();
Do this, it works for me.the trick is to save your hidden field precious id in another hidden input field then build it back using that hidden value.
Markup
<asp:HiddenField ID="HiddenFieldMaster" runat="server" />
<input type="hidden" id="inputHidden" value='<%= HiddenFieldMaster.ClientID%>' />
Javascript
$(function() {
$(".primaryStaticMenu tr,td").each(function(index) {
$(this).click(function() {
if ($(this).attr("title") != "undefined"
&& $(this).attr("title").length > 0) {
var inputHidden = document.getElementById('inputHidden');
$("#" + inputHidden.value).val($(this).attr("title"));
alert(inputHidden.value);
//return false;
}
});
});
});
Code Behind
String Get_cng_value = HiddenFieldMaster.Value;
I have written the code on
ascx script:
<script src="JScripts/jquery.alerts-1.1/jquery.alerts.js" type="text/javascript"></script>
<script>
$(function() {
$('#ImageButton1').click(function() {
jAlert('Please enter a valid Suggestion ID.', 'Case Entry');
});
});
</script>
and on
Code behind:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "callAlert();", true);
the problem is alert box is automatically getting disabled after some time when page load fully
What could be the reason that the alert box is being disable after clicking on OK button and how to call the callAlert function in proper way.
If you are using Master page or pages then you won't get the Client Id of the button as you are declared it should be declared as $('#<%=ImageButton1.ClientID%>') or $('[id$=ImageButton1]') hope it will solve you problem.
$(document).ready(function(){
$('#<%=ImageButton1.ClientID%>').click(function() {
alert('Please enter a valid Suggestion ID.', 'Case Entry');
});
});
You can try to put the following line before the function
$(document).ready(function() {
This will make it:
$(document).ready(function() {
$('#ImageButton1').click(function() {
jAlert('Please enter a valid Suggestion ID.', 'Case Entry');
});
});
});
If you wait till the page is ready, the alert box won't be overwritten (I hope x)).
Also when you check that text box, check if the condition is false, then give the alert.
Is the condition not false? Build in a check to check if the condition is really true. If so? Redirect.
EDIT:
var answer = Confirm: ("This page will now redirect. Are you ready?")
if (answer)
//redirect
else
return
OK, so first it's important to understand that $(function(){... and $(document).ready(function() {... are equivalent, and nothing inside either will execute until the page is fully loaded. In other words, there's no need to use
Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "callAlert();", true);
That can be removed. Also, I see that you're probably using web forms. Be mindful that the Id attribute that will be rendered is not equal to the Id of the control attribute. In other words, if you have a runat="server" control with an Id of ImageButton1, using the syntax $('#ImageButton1') in your jQuery won't work.
Taking this into account, I've added an example below that uses selectors based on class attributes.
<script type="text/javascript">
$(function () {
$('.ImageButton1').click(function (e) {
var text = $('.TextBox1').val();
var redirect = true;
if (!text) {
redirect = confirm('Empty...are you sure?');
}
if (redirect) {
window.location.href = 'http://your-redirect-here.com';
}
});
});
</script>
<input class="TextBox1" type="text" />
<input class="ImageButton1" type="button" value="Click" />
That should get you where you want to go. Let me know if you have any questions.
var answer = Confirm: ("This page will now redirect. Are you ready?")
if (answer)
{
//redirect
} else
{
return false;
}
Put this after jAlert Box:
return false;
And call the function like this:
return callAlert();
I am having a problem with disabling DropDownList based on the chice of 1st DropDownList, there is no post back occuring, and it is a template based web app here is the current code:
<script type="text/javascript">
$(function() { var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>'); dropDownList1.change(function(e) {
if ( jQuery("#ddlUserType").val() != "ETOC") dropDownList2.removeAttr('disabled'); e.preventDefault();
else
dropDownList2.removeAttr('enabled'); e.preventDefault(); }
} );
</script>
what is happening now is page is blank and if I remove the above code everything shows, where I am going wrong.
here is the plain and final javascript code which worked:
<script language="javascript">
function CheckDropDownState(lstbox)
{
if (lstbox.selectedIndex == 3) { document.forms[0].ddlMember.disabled = 1; }
else { document.forms[0].ddlMember.disabled = 0; }
}
</script>
and thew .aspx code:
<asp:dropdownlist id="ddlUserType" runat="server" onclick="CheckDropDownState(this);"></asp:dropdownlist>
Once again appreciate the help guys.
I've tried cleaning your code a little bit:
$(function() {
var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>');
dropDownList1.change(function(e) {
var selectedValue = $(this).val();
if (selectedValue != 'ETOC') {
// enable the second combo if the value selected in the first combo
// is not ETOC
dropDownList2.removeAttr('disabled');
} else {
dropDownList2.attr('disabled', 'disabled');
}
e.preventDefault();
}
});