Posts

Showing posts with the label ajax

Silverlight: Simple way to create call back method.

The Simple way to create a call back method in .Net. also you can pass on the value to the callback object inside the another call backmethod to your callbackmethod. Private Guid userId; public void SaveAndComplete(bool complete, Action onComplete) { userId= //One more callback method. _dc.SubmitChanges(SaveCompleted, onComplete); } private void SaveCompleted(SubmitOperation so) { if (!so.HasError) { //this is where you can pass on the value to the call back method. ((Action)so.UserState)(UserId); } else { //Error message } } Calling the callback method "SaveAndComplete" private void Save_Click(object sender, RoutedEventArgs e) { SaveAndComplete(false, SavedSuccessFully); } private void SavedSuccessFully(Guid generatedID) { //here you will get the value which you hve passed from the callback method. if (generatedAssessmentID == Guid.Empty) return; }

Silverlight: Finding Parent control

The problem the UserControl's parent is not the ChildWindow, its the Grid inside the child window. You need to get the parent of the parent of the UserControl to navigate to the ChildWindow:- ChildWindow cw = (ChildWindow)((FrameworkElement)this.Parent).Parent; However embedding this in your UserControl would bad practice, you would be stipulating to the consumer of your UserControl where the it can be sited. In the above case for the user control to work it would need to always be a direct child of the Layout root. A better approach would be to search up the visual tree looing for a ChildWindow. I would use this helper method (actually I'd place this in a helper extensions static class but I'll keep it simple here). private IEnumerable Ancestors() { DependencyObject current = VisualTreeHelper.GetParent(this); while (current != null) { yield return current; current = VisualTreeHelper.GetParent(current); } } Now you can use LINQ methods to get the...

Silverlight: Normal Properties vs. Dependency Properties

In the Silverlight development world there are two kinds of properties that you can have on a Silverlight control: normal C# properties and dependency properties. The normal C# properties are added to a Silverlight control the same way as they would be added to any C# class: public string MyProperty { get; set; } And then in XAML, you could set the value of the property like this: <MyControl MyProperty= "someValue" /> This works fine for setting specific values in templates that are unlikely to change or if they do change then the change is always manually made to the XAML file. But what happens if you want to have the value of the property bound to some other value that is retrieved from a database, web service, etc? You might try Binding to the property like so: <MyControl MyProperty= "{Binding DynamicPropertyValue}" /> Where DynamicPropertyValue was a property on the parent element that you wanted to to have your pro...

ASP.Net MVC: Loading Bootstrap Modal Dialog content with jquery ajax.

Whenever i tried t find how to load the bootstrap modal dialog content at runtime, i was unable to find proper solution anywhere.  One way to do it but in that you have no contrl over the error as bootstrap automatically do that.   $(".opentutorial").click(function (e) {             e.preventDefault();             $('#modalHelpDiv').load(anyurl);             $('#modalHelpDiv').modal({ show: true, keyboard: false });             //.dialog(opt).dialog("open");         }); Second way is this and as per me this second way is the best. <div id="modalDiv" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-href="anyurl"></div> $('.previewbtn').click(function () {                 var url = $(this).attr('data-href'); ...

ASP.Net MVC: Creating an AutoComplete with Images for profile with MVC and Jquery

Sometime we need to create a autocomplete textbox in our projects, whihc containes images of the user. whether its MVc or Asp.net. JqueryUI have a control for this and you can leverage to make your wish fullfil. its need a Array of data. Here is the solution how to do that. You need to take the reference of the latest jqueryui script. On the View < input type ="text" id ="txtUserSearch" /> < script type ="text/javascript">     $(document).ready( function () {         $( '#txtUserSearch' ).autocomplete({             source: ' @ Url.Action( " GetMatchingUser " , "Home" ) ' ,             minLength: 1,             select: function (event, ui) {                 window....