Call javascript from vb.net code behind

If DataStore.Record.Exists(theRecord) Then Dim script As String = “alert(‘Record exists’)” If Not Page.ClientScript.IsStartUpScriptRegistered(Me.GetType(), “alertscript”) Then Page.ClientScript.RegisterStartUpScript(Me.GetType(), “alertscript”, script, True) End If End If you would do it like above, where you should replaceDataStore.Record.Exists(theRecord) with condition that checks database record exists

Calling javascript from code behind

Assuming that the pre-conditions are true. You need to pass an additional parameter to the RegisterClientStartupScript method call to indicate that scriptTags need to be added. Page.ClientScript.RegisterStartupScript(this.GetType(), “openCredentials”, string.Format(“radopen(‘Services.aspx?clientId={0}, Window_Services’)”, openCredentialsWindow_ClientId.ToString()),true);

how to access master page control from content page

In the MasterPage.cs file add the property of Label like this: public string ErrorMessage { get { return lblMessage.Text; } set { lblMessage.Text = value; } } On your aspx page, just below the Page Directive add this: <%@ Page Title=”” Language=”C#” MasterPageFile=”Master Path Name”….. %> <%@ MasterType VirtualPath=”Master Path Name” %> // Add this … Read more

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 do I access an element of a control template from within code-behind

You need to get the template and locate the control by name on the templated control, something like: var template = MyList.Template; var myControl = (MyControl)template.FindName(“MyControlName”, MyList); Templates are just that: Abstract descriptions of what is to be created, the controls in templates only exist in the context of something that is being templated. Note … 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 }