code-behind

ASP.NET Web Application Message Box

蹲街弑〆低调 提交于 2019-11-27 01:33:06
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 to the user? Example usage of this: I have a button that loads a file in the code behind. When the file is loaded or if there is an error I would like to popup a message to the user stating the result. Any ideas on this? You want to use an Alert. Unfortunately it's not as nice as with windows forms. ClientScript.RegisterStartupScript(this.GetType(),

Adding css class through aspx code behind

烂漫一生 提交于 2019-11-27 01:32:18
问题 I am using aspx. If I have HTML as follows: <div id="classMe"></div> I am hoping to dynamically add a css class through the code behind file, ie on Page_Load. Is it possible? 回答1: If you want to add attributes, including the class, you need to set runat="server" on the tag. <div id="classMe" runat="server"></div> Then in the code-behind: classMe.Attributes.Add("class", "some-class") 回答2: If you're not using the id for anything other than code-behind reference (since .net mangles the ids), you

How to I access an attached property in code behind?

 ̄綄美尐妖づ 提交于 2019-11-27 00:32:42
问题 I have a rectangle in my XAML and want to change its Canvas.Left property in code behind: <UserControl x:Class="Second90.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" KeyDown="txt_KeyDown"> <Canvas> <Rectangle Name="theObject" Canvas.Top="20" Canvas.Left="20" Width="10" Height="10" Fill="Gray"/> </Canvas> </UserControl> But this doesn't work: private void txt_KeyDown(object sender,

Calling javascript from code behind

被刻印的时光 ゝ 提交于 2019-11-26 23:20:18
I have a c# asp.net 3.5 app I am trying to open a window from code behind after a certain event. I have this but its not working and there are no errors in firebug protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (openCredentialsWindow) { if (openCredentialsWindow_ClientId != Guid.Empty) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "openCredentials", string.Format("radopen('Services.aspx?clientId={0}, Window_Services')", openCredentialsWindow_ClientId.ToString())); } } } Any ideas? Assuming that the pre-conditions are true. You need to pass an

Create DataTemplate in code behind

雨燕双飞 提交于 2019-11-26 20:21:18
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 achieve this? I know that there are other ways of addind data template in code behind 1. create a data template in XAML and load it on code behind 2. create and add using XamlParser but i need to do in the way i showed in example. Need some help. Russell Giddings Although Archedius's method works, officially it is deprecated and instead recommended

populate treeview from list of file paths in wpf

血红的双手。 提交于 2019-11-26 20:09:09
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 make it work but it will be nice if I could do the same thing with a wpf treeview control. The tree view that I want to construct consists of about 50,000 files therefore I think it will be better if it is bind it to something. But first before binding it, I think it will be helpful to construct one based on a List of strings (strings contains the

Accessing a resource via codebehind in WPF

丶灬走出姿态 提交于 2019-11-26 18:16:48
问题 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,

How to access a JavaScript variable from code behind in asp.net

拜拜、爱过 提交于 2019-11-26 17:49:55
问题 i am using a JavaScript and it have the below code: <script type="text/javascript"> var count = 0; jQuery('td').click(function () { if ($(this).hasClass('process')) { count = count+100; alert('count'); } }); </script> so if its click the value is added by 100 i check using an alert, now how to access the var count in my code-behind 回答1: You will need to store the count variable on a server-side control in order to do this. Example: <script type="text/javascript"> var count = 0; jQuery('td')

Binding String Property in Code-Behind TextBlock

佐手、 提交于 2019-11-26 17:47:44
问题 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 . 回答1: Use BindingOperations Binding binding = new Binding(); binding.Path = new PropertyPath(

How do I access an element of a control template from within code-behind

痞子三分冷 提交于 2019-11-26 17:28:33
I'm trying to access a user control which is inside the control template of a content control. Specifically: <ContentControl x:Name="MyList" > <ContentControl.Template> <ControlTemplate x:Name="MyControlTemplate"> <Border RenderTransformOrigin="0,0" x:Name="border"> <UserControls:MyControl x:Name="MyControlName" Width="100" ViewModel="{Binding}" /> I can access this.MyList but it says this.MyControlName is not found. How do I access the MyControlName object from code-behind in this situation? Thanks! You need to get the template and locate the control by name on the templated control,