|
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
First, this is my first ever attempt ay writing JavaScript, so forgive my ignorance...
My app is listening to a SignalR service. When the server hub calls "NotifyAllClientsOfChanges" I want my WebGrid to be reloaded. I'm getting an exception.
1) The Controller code:
public class HomeController : Controller
{
private IDataAccess _dal;
private DashboardClientProxy _dashboardProxy;
public HomeController()
{
_dal = new DataAccess();
_dashboardProxy = new DashboardClientProxy();
try
{
_dashboardProxy.Connect();
}
catch (Exception e)
{
throw e;
}
}
public ActionResult Index()
{
var data = GetData();
return View(data);
}
public IEnumerable<AssayDashboardInfoEntity> GetData()
{
var data = _dal.GetDashboardInfos(new DashboardInfoQueryArgs());
return data;
}
}
2) Next my JS code.
<script language="javascript">
$(function () {
<pre>
proxy.client.NotifyAllClientsOfChanges = function () {
var searchUrl = "Home/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
};
});</pre>
3) When I run it I get
var searchUrl = "Home/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
$("#btnSearch").attr({ 'value': 'Search' });
}
});
Unhandled exception at line 59, column 5 in http:
0x800a1391 - JavaScript runtime error: '$' is undefined
Someone please help. What am I doing wrong???
Line 59 is the "$(function () {" line
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 2-Mar-17 13:44pm.
|
|
|
|
|
The error says $ is not defined. $ is, typically, the jQuery function.
$(function () {...}); is jQuery's startup function (goes off when the entire page loaded), but it seems you never loaded jQuery.
So make sure to include jQuery in your scripts before any of your own code.
|
|
|
|
|
You're right. I didn't have
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js" "></script>
<!--Reference the SignalR library. -->
<script src="/Scripts/jquery.signalR-2.0.0.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
I put this just after the tag. And I moved my function right below all of that, so I now have:
<body>
<pre>
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.6.4.min.js" "></script>
<!--Reference the SignalR library. -->
<script src="/Scripts/jquery.signalR-2.0.0.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
proxy.client.NotifyAllClientsOfChanges = function () {
var searchUrl = "Home/GetData";
$.ajax({
url: searchUrl,
type: "POST",
success: function (data) {
$("#divData").html(data);
}
});
};
});
I then got this.
So I fixed the jquery version, so I now have:
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-1.10.2.min.js" "></script>
<!--Reference the SignalR library. -->
<script src="/Scripts/jquery.signalR-2.2.1.js"></script>
Now I get
" jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file."
The jquery script if referenced first. What else could be wrong?
[UPDATE]
Going to start a new question
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Is it on the top in the scripts hierarchy? It should be.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
hi all,
please help me to solve this .
i am using windows 7 for development with vs2010, have one application(wpf) which is running proper with click on .exe, but when i used to call same by some third-party application which is made by using win Xp- service pack -03, shows white stable popup which is not movable and appearance till application closed, other all functionalities of application runs smoothly only this popup appearance.
|
|
|
|
|
Member 12270195 wrote: call same by some third-party application You need to talk to the people who wrote that application.
|
|
|
|
|
Hello,
I have the following control that uses Localization.
I have defined ResPropName in the English resource file as EnglishProperty and in the Spanish Resource file as SpanishProperty. Both properties are defined in the mySource.
Issue: When I try to switch languages, the Content of the checkboxes appears as SpanishProperty or EnglishProperty.
If I would replace the listbox with a combobox the language would switch and the proper text appears.
I have done the same test on one single check-box and I got the same issue.
It seems that the Content property of the Checkbox is not resolving the property while the DisplayMemberPath of the Combobox does.
Come on Guys. I really need help with this one.
<UserControl x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:local="clr-namespace:WpfApplication2"
LocalizationScope.ResourceManager="{ResourceManager AssemblyName=WpfApplication2, BaseName=WpfApplication2.Resources.WpfApplication2Resources}"
mc:Ignorable="d" Height="350" Width="525">
<Grid>
<ListBox Name="listBox" ItemsSource="{Binding mySource}">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Name="CheckBox" Content="{Loc ResPropName}">
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
<ComboBox ItemsSource="{Binding mySource}" DisplayMemberPath="{Loc ResPropName}" />
modified 15-Feb-17 12:33pm.
|
|
|
|
|
Hi,
I included DialogService in my Window to call other view which contains User input values
What I need is to prevent closing this dialog until input are validated.
_roleViewModel = new Role_ViewModel(eTypeOperation);
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
var cancelCommand = new UICommand
{
Id = MessageBoxResult.Cancel,
Caption = Properties.Resources.CstCancel,
IsCancel = true,
IsDefault = false,
};
RoleService.ShowDialog(new List<UICommand> { createCommand, cancelCommand }, Properties.Resources.CstNewRole, _roleViewModel);
private IDialogService RoleService
{
get { return GetService<IDialogService>("RoleServiceDialog"); }
}
the CanCreateRole control the state of Button "OK" regarding input user But What I need is to :
When click OK button , we should check data (user input) if it is ok we return and close the DialogService otherwise we should display messagebox and stay on this DialogService (don't close) until press "Cancel"
Thank you
|
|
|
|
|
In your CanCreateRole method, validate the input, and return false if the input is not valid.
In your CreateRole method, call CanCreateRole to validate the input, and if it's not valid, don't close the dialog.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
But this did'nt solve my problem
because what I need is :
- let user enter some data (if no data => the button still disabled related to
CanCreateRole - when there is data click on Button "OK"
- if the data are valid against condition we do nothing and the DialogService close (normal behavior)
ELSE (data not valid ) we display messagebox and the DialogService is still shown with last data entered.
|
|
|
|
|
So do your extra validation in the CreateRole method, and don't close the dialog if it fails.
Or are you saying that the dialog always closes after invoking the command? If that's the case, we'll need to know what the implementation of your dialog service looks like.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
the code of command is as described in the first question :
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
|
|
|
|
|
Yes, but we can't see your dialog service code.
If it's something you've written, then you need to show the relevant parts of the code.
If it's something you got from an article or GitHub project, then we'll need a link to the source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In my MainWindow.xaml (which will validate data after click on OK )
<pre> <dxmvvm:Interaction.Behaviors>
<dx:DXMessageBoxService />
<dxmvvm:CurrentWindowService Window="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}" />
<dx:DialogService DialogWindowStartupLocation="CenterOwner" Name="RoleServiceDialog">
<dx:DialogService.ViewTemplate>
<DataTemplate>
<views:Role_View></views:Role_View>
</DataTemplate>
</dx:DialogService.ViewTemplate>
</dx:DialogService>
</dxmvvm:Interaction.Behaviors>
in MainWindow.cs (the ViewModel related to the MainWindow.xaml)
_roleViewModel = new Role_ViewModel(eTypeOperation);
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand(CreateRole, CanCreateRole)
};
var cancelCommand = new UICommand
{
Id = MessageBoxResult.Cancel,
Caption = Properties.Resources.CstCancel,
IsCancel = true,
IsDefault = false,
};
RoleService.ShowDialog(new List<UICommand> { createCommand, cancelCommand},Properties.Resources.CstNewRole, _roleViewModel);
private void CreateRole()
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
}
private bool CanCreateRole()
{
return !string.IsNullOrEmpty(_roleViewModel.RoleName.Trim());
}
|
|
|
|
|
So you're using the DevExpress MVVM framework?
Looking at the documentation[^], your command can take a CancelEventArgs parameter to allow it to keep the dialog open:
Note that dialog commands take a CancelEventArgs object as a parameter. When dialog commands are invoked, the dialog is closed by default. To prevent this behavior, it is necessary to set the CancelEventArgs.Cancel parameter to True.
var createCommand = new UICommand
{
Id = MessageBoxResult.OK,
Caption = Properties.Resources.CstOk,
IsCancel = false,
IsDefault = true,
Command = new DelegateCommand<CancelEventArgs>(CreateRole, CanCreateRole)
};
private bool CanCreateRole(CancelEventArgs e)
{
return !string.IsNullOrWhiteSpace(_roleViewModel.RoleName);
}
private void CreateRole(CancelEventArgs e)
{
_roleViewModel.AcceptChanges();
if (ValidateData(_roleViewModel.RoleName.Trim()))
{
AddRole(_roleViewModel.RoleName, _roleViewModel.RoleDescription);
}
else
{
e.Cancel = true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great, saved me
|
|
|
|
|
I'm fairly to WPF and C# and slowly learning its vastness.
What I thought would be easy doesn't seem so easy to my brain. Here's my checkbox XAML:
<DataGridTemplateColumn Width="SizeToHeader" Header="FAI">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=fai}" Checked="FAI_CheckBox_Checked" Unchecked="FAI_CheckBox_Unchecked" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
And after ticking this I want to check another checkbox, which is currently:
<DataGridCheckBoxColumn Binding="{Binding Path=user_fai}" Width="Auto" Header="User FAI" Visibility="Visible" IsReadOnly="True"/>
So, for the first checkbox, I have my events created, but no idea now how to proceed, even after much searching the internet for an answer. Is this the correct route? Can it all be done in XAML?
|
|
|
|
|
If you always want the two checkboxes to have the same state, why not bind them to the same member?
<CheckBox IsChecked="{Binding Path=fai}" />
<CheckBox IsChecked="{Binding Path=fai, Mode=OneWay}" IsReadOnly="True" Width="Auto" Header="User FAI" Visibility="Visible" />
Otherwise, use the view model:
public bool fai
{
get { return _fai; }
set
{
_fai = value;
OnPropertyChanged();
if (value) user_fai = true;
}
}
Model-View-ViewModel (MVVM) Explained[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for your help Richard. I have indeed decided to go down the MVVM path, so thank you for the pointer.
|
|
|
|
|
I have my WPF main project, and have a second project called Controls. Controls is referenced i the main project.
In controls I have a UserControl called HyperlinkView:
<TextBlock>
<pre>
<Hyperlink Command="{Binding LinkClickCommand}"
Click="Hyperlink_Click">
<TextBlock Text="{Binding LinkText}"/>
</Hyperlink>
There are 2 DP's in the code behind for the LinkText and LinkClickCommand, as well as the event handdler for the Click.
Now in my Main project I an dynamically added these HyperlinkView controls at run time.
The question is this... How do I apply a style to this control from within the Main project? For this control I may want the font size to be 24 and the foreground to be Teal. How do I apply styling to both the hyperlink and the textbox from within my Main project?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The easiest way would be to create a named style and apply that. This would be applied to the TextBlock inside your HyperLink.
This space for rent
|
|
|
|
|
So give both the Link and textblock names, then create a named style for them in my Main project?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
But in the style, how do you specified which element in the control the style items are applied to?
How do you apply a stlye to each of the elements in the control from with in the style?
<Style x:Key="HyperlinkViewStyle"
TargetType="{x:Type myControls:HyperlinkView}">
How do do style the TextBlock or the Hyperlink in here?
</Style>
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 2-Feb-17 13:57pm.
|
|
|
|
|
I realize that this is not a Telerik forum but I also poured through their forums to no avail. Long story short, I am using NHibernate to hydrate my viewmodels and exposing complex objects with their related objects to my view. The issue is that in my grid I have a combobox column that has a collection of objects from the viewmodel, the selectedvalue of which will update the object of the selected item. When I change the combobox everything is great, everything is talking back and forth, all is well. But when I close the control and reopen it, it does not select any value for the column.
All code is cut for brevity:
View:
<telerik:GridViewComboBoxColumn x:Name="Client"
ItemsSource="{Binding Clients}"
DataMemberBinding="{Binding Client}"
DisplayMemberPath="Name"
SelectedValueMemberPath=""
Header="Client"
Width="125" />
ViewModel:
public ObservableCollection<Client> Clients { get; private set;}
Entity:
public class Claim : Entity<int>
{
public virtual Client Client { get; set; }
}
NHibernate Mapping
public ClaimMap()
{
Table("Claim");
LazyLoad();
Id(x => x.Id).GeneratedBy.Identity().Column("id");
References(x => x.Client).Column("clientId").Not.Nullable();
}
}
}
I am sure I could just expose the id values on the Claim object and wire it up that way but it really is swimming against the current of NHibernate to do so.
Thoughts?
Cheers, --EA
|
|
|
|
|