Create DataTemplate in codebehind

Although Archedius’s method works, officially it is deprecated and instead recommended way to programmatically create a template is to load XAML from a string or a memory stream using the Load method of the XamlReader class like this… public DataTemplate Create(Type type) { StringReader stringReader = new StringReader( @”<DataTemplate xmlns=””http://schemas.microsoft.com/winfx/2006/xaml/presentation””> <” + type.Name + @” … Read more

How to call a C# function from JavaScript?

You can use a Web Method and Ajax: <script type=”text/javascript”> //Default.aspx function DeleteKartItems() { $.ajax({ type: “POST”, url: ‘Default.aspx/DeleteItem’, data: “”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (msg) { $(“#divResult”).html(“success”); }, error: function (e) { $(“#divResult”).html(“Something Wrong.”); } }); } </script> [WebMethod] //Default.aspx.cs public static void DeleteItem() { //Your Logic }

Creating a Style in code behind

You need to add setters to the style rather than using RegisterName. The following code, in the Window_Loaded event, will create a new TextBlock style which will become the default for all instances of a TextBlock within the Window. If you’d rather set it explicitly on one particular TextBlock, you can set the Style property … Read more

Parser Error: Server Error in ‘/’ Application

Right-click your Global.asax file and click View Markup. You will see the attribute Inherits=”nadeem.MvcApplication”. This means that your Global.asax file is trying to inherit from the type nadeem.MvcApplication. Now double click your Global.asax file and see what the class name specified in your Global.asax.cs file is. It should look something like this: namespace nadeem { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)