code-behind

Passing arguments to JavaScript function from code-behind

99封情书 提交于 2019-11-27 15:06:18
I would like to call a javascript function from an aspx control. For instance, suppose I had: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function test(x, y) { } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click"/> </div> </form> </body> </html> and in the code behind: protected void Button1_Click(object sender, EventArgs e) { // do stuff (really going to a database to fill x and y) int[] x = new int[] { 1, 2, 3, 4, 5 };

Accessing a resource via codebehind in WPF

可紊 提交于 2019-11-27 13:24:06
I have a custom collection defined in my window resources as follows (in a Sketchflow app so the window is actually a UserControl): <UserControl.Resources> <ds:MyCollection x:Key="myKey" x:Name="myName" /> </UserControl.Resources> I want to be able to refer to this collection in the codebehind, which I expected would be by the x:Name, but I can't seem to access it. I can get a reference to it using myRef = (MyCollection) this.FindName("myKey"); but this seems hackish. Is this bad practice, and what would be better? Thanks :) japf You should use System.Windows.Controls.UserControl 's

XAML or C# code-behind

£可爱£侵袭症+ 提交于 2019-11-27 10:07:52
问题 I don't like to use XAML. I prefer to code everything in C#, but I think that I am doing things wrong. In which cases it is better to use XAML and when do you use C#? What is your experience? 回答1: Creating an entire window in C# can be a mess of code. The best thing about WPF is that XAML allows you to separate your design from your logic, making for much easier-to-read code. I'll use C# when I need to create dynamic controls, but I tend to keep my general design, static storyboards, styles,

Binding String Property in Code-Behind TextBlock

社会主义新天地 提交于 2019-11-27 08:52:09
i am trying to binding a very simple property to a TextBlock, but I have to do all in code-behind (C#). What i am trying to do is: public string SomeText { get; set; } And after I try the Binding on TextBlock: Binding myBinding = new Binding(SomeText); myTextBlock.SetBinding(TextBlock.TextProperty, myBinding); How do I keep the Text property of the TextBlock the same of the Property SomeText . Use BindingOperations Binding binding = new Binding(); binding.Path = new PropertyPath("SomeText"); binding.Source = sourceObject; // view model? BindingOperations.SetBinding(theTextBlock, TextBlock

Creating a Style in code behind

邮差的信 提交于 2019-11-27 07:25:53
Does anyone know how to create a wpf Style in code behind, I can't find anything on the web or MSDN docs. I have tried this but it is not working: Style s = new Style(typeof(TextBlock)); s.RegisterName("Foreground", Brushes.Green); s.RegisterName("Text", "Green"); breakInfoControl.dataTextBlock.Style = s; 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

How to Set Image Resource URI from Code-Behind

自作多情 提交于 2019-11-27 06:44:56
问题 I am trying to embed a PNG graphic into a DLL and load it into an Image control as a BitmapImage. However, WPF keeps throwing an exception saying that the resource cannot be found. First, some minimal sample code and the steps to reproduce the problem: Create a WPF project named ImageResTest with an empty main window (you can set the default namespace to ImageResTest ). The code-behind file of the main window should look like this: using System; using System.Windows; using System.Windows

HyperLink with NavigateUrl with Eval(). Where is the mistake?

自作多情 提交于 2019-11-27 06:35:12
问题 First I was changing HyperLink.NavigateUrl in code-behind on Page_Load() . But after I decided to do it in design using Eval() method. <asp:HyperLink runat="server" NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" /> or <asp:HyperLink ID="urlRefuse" runat="server" NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" /> where id and type - are variables from Request . But it

Unable to call App_Code class from a code-behind

女生的网名这么多〃 提交于 2019-11-27 04:59:27
I have a class in a file that's in the "App_Code" folder. I'm able to use this in an "aspx" file but not from a code-behind file. How do I make it visible to a code-behind? NOTE: This is ASP.Net on Mono and I'm writing the classes directly, not using an IDE to compile them My files: ASPX FILE (testappcode.aspx) <%@ Page language="c#" src="TestAppCode.aspx.cs" Inherits="TestAppCode.TestAppCode" AutoEventWireup="true" %> <html> <head> <title>Test App_Code Folder</title> </head> <body> <form id="contactForm" runat="server"> <asp:TextBox id="Name" runat="server" ></asp:TextBox> <asp:TextBox id=

Set Text property of asp:label in Javascript PROPER way

一曲冷凌霜 提交于 2019-11-27 03:47:54
问题 I have a series of textboxes on a form. When the user inserts numbers into these textboxes, calculations are made and <asp:Label> controls are updated via JavaScript to reflect these calculations: document.getElementById('<%=TotalLoans.ClientID %>').innerHTML = TotalLoans; This correctly updates the UI. However, when I try to access the value in the codebehind, the Text property is empty. This makes sense I guess, since I was updating the innerHTML property via the JavaScript. //TotalLoans

OnDataBinding vs Inline: pros, cons and overhead

情到浓时终转凉″ 提交于 2019-11-27 02:48:04
问题 I thought I would ask this question to see why many examples and people prefer to use inline databinding in the aspx code vs implementing an OnDataBinding event when using WebForms. For any databound control (eg. Repeater, GridView, etc) I always implement the OnDataBinding method for field level controls if I need to do anything that isn't built in out of the box (eg. I need to do an Eval). Most examples I see have the code right in the aspx page using the inline <%# syntax. Example of