code-behind

Finding the default style for a type in code behind

倖福魔咒の 提交于 2019-12-18 20:09:23
问题 In WPF, you can create a Style that acts as the default for a control type in XAML: <Style TargetType="{x:Type local:MyControl}"> . . . </Style> Then, when WPF goes to display that control, it looks up that Style from the resources based on the its type. I want to do the equivalent of this in the code-behind of my program. How do I find that Style ? 回答1: You can search for the style in the Application-level resources by using the control type as the key: Style defaultStyle = Application

Animate Margin / Thickness

自古美人都是妖i 提交于 2019-12-17 20:08:05
问题 I just thought I already know how WPF and XAML Syntax works.... wrooong. I got the message: 'WithEvents' variables can only be typed as classes, interfaces or type parameters with class constraints. Please, do you know why this syntax is wrong? I need to use the single value as double. It works later with an storyboard in codebehind. Regards I just want to animate the Red rectangle with a storyboard in location and size. Perhaps XAML is the right solution anyway? 回答1: To animate thickness,

ASP.Net Open New Tab in Browser from CodeBehind

跟風遠走 提交于 2019-12-17 19:34:41
问题 I need to open a browser tab from a link that is given to me by an asp.net code behind. Normally I would have a link and target="_blank" , but the link that I need is dynamic, so I must have the behavior of a _blank link from code behind. Any Ideas? 回答1: If you have the data needed to create the link when generating the initial HTML, you can do something like this in the Page_Load event: protected void Page_Load(object sender, EventArgs e) { Button1.OnClientClick="javascript:window.open(

Difference between page_load and onLoad

眉间皱痕 提交于 2019-12-17 18:37:15
问题 What is difference between page_load and onLoad functions in ASP.NET codebehind? 回答1: Load is the event and OnLoad is a method that raises that event when called it's just base class implementation that does it of course, and therefore needs to be called from deriving classes so that events work) 回答2: You should probably read the Page Lifecycle Overview for more info. This little bit should help clear up the difference: Note that when an event handler is created using the Page_event syntax,

Redirect to another page using Post method from Code behind

北城以北 提交于 2019-12-17 16:27:21
问题 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 values and save some thing in db in code behind. how can I implement this? If I can post data to another page on my app and can submit that page programmically it maybe help me. Thanks 回答1: string url = "3rd Party Url"; StringBuilder postData = new

Parser Error: Server Error in '/' Application

非 Y 不嫁゛ 提交于 2019-12-17 16:00:33
问题 I got the following error: "An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately." Parser Error Message: `Could not load type 'nadeem.MvcApplication'`. Source Error: Line 1: <%@ Application Codebehind="Global.asax.cs" Inherits="nadeem.MvcApplication" Language="C#" %> 回答1: Right-click your Global.asax file and click View Markup . You will see the attribute Inherits

how to add a code-behind page to a view or partial view

喜你入骨 提交于 2019-12-17 15:44:43
问题 I notice with the latest version of ASP.NET MVC that a View no longer defaults to having code-behind classes. How do I go about adding a code-behind class now to a View or Partial View?? 回答1: How to add a Code-behind page to a Partial View Seems this wasn't particularly tricky, and is quite do-able. This answer worked for a Partial ViewUserControl but the same should apply for a Normal MVC ViewPage as well Add a new Class file with the convention of <view filename & extention>.cs (i.e. view

Call javascript from vb.net code behind

偶尔善良 提交于 2019-12-17 09:53:50
问题 How can I call a javascript function from code behind? The most popular response is " ScriptManager.RegisterStartupScript " however, that does not work in my situation. I have a vb class that is doing a database check to see if a record exists. If exists, then call a javascript function to display an alert("Record exists") So I am doing something like Dim strMessage as string = "javascript:RecordExists('Param');" How do I call this function from my vb.net class? 回答1: If DataStore.Record

Creating a Style in code behind

给你一囗甜甜゛ 提交于 2019-12-17 09:22:18
问题 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; 回答1: 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

how to access master page control from content page

断了今生、忘了曾经 提交于 2019-12-17 05:01:02
问题 I have a master page which contains a label for status messages. I need to set the status text from different .aspx pages. How can this be done from the content page? public partial class Site : System.Web.UI.MasterPage { public string StatusNachricht { get { return lblStatus.Text; } set { lblStatus.Text = value; } } protected void Page_Load(object sender, EventArgs e) { } } I have tried this, but was unsuccessful in making it work: public partial class DatenAendern : System.Web.UI.Page { var