Questions tagged [code-behind]

Code-behind refers to code for your UI (Windows Forms, ASP.NET page, etc.) contained within a separate class file. This allows separation of the UI and the logic behind it.

Code-behind refers to code for your UI (Windows Forms, ASP.NET page, etc.) contained within a separate class file. This allows separation of the UI and the logic behind it.

1955 questions
37
votes
6 answers

Programmatically add a span tag, not a Label control?

How can I add a span tag from a code behind? Is there an equivalent HtmlControl? I am currently doing it this way. I am building out rows to a table in an Itemplate implementation. var headerCell = new TableHeaderCell { Width =…
Hcabnettek
  • 12,678
  • 38
  • 124
  • 190
36
votes
13 answers

ASP.NET Web Application Message Box

In an asp.net windows forms application, in the C# code behind you can use: MessageBox.Show("Here is my message"); Is there any equivalent in a asp.net web application? Can I call something from the C# code behind that will display a message box…
Baxter
  • 5,633
  • 24
  • 69
  • 105
36
votes
2 answers

Creating a Style in code behind

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",…
James
  • 3,597
  • 11
  • 47
  • 57
33
votes
2 answers

How to regenerate designer code for all SpecFlow features

I've got ~30 SpecFlow feature files, and I recently removed the Foo.feature.cs files from source control because I got sick of resolving merge conflicts in Designer Generated code. I did not exclude or remove these files from my Visual Studio…
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
33
votes
4 answers

How can I read WPF publish version number in code behind

I want to read and display WPF application publish version number in splash windows, In project properties in publish tab there is publish version, how can I get this and display it in WPF windows. Thanks in advance
Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66
32
votes
4 answers

WPF Bind to class member in code behind

Pretty simple question, but can't seem to find a complete answer on here... I need to databind in xaml to a property of a class member in codebehind.
jaws
  • 1,952
  • 4
  • 20
  • 27
31
votes
7 answers

How to call a C# function from JavaScript?

I want to call CsharpFunction, a C# function in code-behind, from JavaScript. I tried the code below but whether the JavaScript condition is True or False, CsharpFunction was called regardless! JavaScript code: if (Javascriptcondition > 0) { …
IamNumber5
  • 351
  • 1
  • 3
  • 9
30
votes
2 answers

populate treeview from list of file paths in wpf

There are several examples of how to populate a tree view from a collection of file paths such as this or this other example. I cannot seem to find such example for WPF. I know I can integrate windows forms and use a different control in order to…
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
30
votes
3 answers

Create DataTemplate in codebehind

How do i add controls to datatemplates programmatically? For Example. Below I've created TextBlock and DataTemplate. TextBlock text = new TextBlock(); DataTemplate template = new DataTemplate(); Now I need to add TextBlock to DataTemplate. How to…
MYRAO
  • 301
  • 1
  • 3
  • 4
30
votes
5 answers

XAML without the .xaml.cs code behind files

I'm using WPF with the Model-View-ViewModel pattern. Thus, my code behind files (.xaml.cs) are all empty, except for the constructor with a call to InitializeComponent. Thus, for every .xaml file I have a matching, useless, .xaml.cs file. I swear…
Eric
  • 2,029
  • 2
  • 26
  • 36
26
votes
1 answer

Redirect to another page using Post method from Code behind

I want to implement a Payment service.I will create some values in code behind and then by using post method I have to post this values to Payment gateway and user must redirect to that page. I can't Use form action becuase I have to create some…
Ashian
  • 521
  • 2
  • 7
  • 22
25
votes
1 answer

How to use WPF's asterisk size value in codebehind?

I create some control in codebehind and would like to set its size dynamically. I can assign numerical values as well as System.Windows.GridLength.Auto, but there is no equivalent to "*". Is that because the "*" from XAML gets translated into code…
Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
24
votes
6 answers

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

First I was changing HyperLink.NavigateUrl in code-behind on Page_Load(). But after I decided to do it in design using Eval() method.
abatishchev
  • 98,240
  • 88
  • 296
  • 433
24
votes
1 answer

Unable to call App_Code class from a code-behind

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…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
24
votes
7 answers

Set Text property of asp:label in Javascript PROPER way

I have a series of textboxes on a form. When the user inserts numbers into these textboxes, calculations are made and controls are updated via JavaScript to reflect these calculations: document.getElementById('<%=TotalLoans.ClientID…
splatto
  • 3,159
  • 6
  • 36
  • 69