code-behind

How can I two-way bind a TextBox to a code-behind property in ASP.NET?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 18:31:07
问题 I cannot get any new entries in the textbox:txtMyString to set to the property MyString. What am I missing here? <asp:TextBox ID="txtMyString" Text='<%# MyString %>' runat="server" /> private string myString; protected string MyString { get { return myString; } set { myString = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) myString = "1 way test works"; DataBind(); } 回答1: If you're doing two-way databinding, you need to use the Bind() method of the

C# data binding doesn't update WPF

微笑、不失礼 提交于 2020-01-03 17:31:18
问题 I'm trying to do a Data Binding in the C# code behind rather than the XAML. The XAML binding created in Expression Blend 2 to my CLR object works fine. My C# implementation only updates when the application is started after which subsequent changes to the CLR doesn't update my label content. Here's the working XAML binding. First a ObjectDataProvider is made in my Window.Resources. <ObjectDataProvider x:Key="PhoneServiceDS" ObjectType="{x:Type kudu:PhoneService}" d:IsDataSource="True"/> And

How to create multiple code behind file for .aspx page

六月ゝ 毕业季﹏ 提交于 2020-01-02 06:46:15
问题 I have a situation where I need to create multiple code behind files for a single .aspx page in c# asp.net. Actually I have a web form on that huge coding is done and I need multiple developer's working on it simultaneously. How can I achieve the same? Here is the code snippet I tried Class 1 MyPartialClass.cs namespace WebApplication1 { public partial class Default : System.Web.UI.Page { protected void PrintText(string pt) { Response.Write(pt); //lblTest.Text = pt; //Can not access this

mvc no codebehind strongly typed viewdata headers not working

旧巷老猫 提交于 2020-01-02 04:07:28
问题 I add that to my header <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> and am able to access ViewData and all its internals as well as all the mvc objects like url and html. As soon as I add " System.Web.Mvc.ViewPage<app.Models.tTable> " I have no access to any mvc classes and helper methods. I am confused on why this is. I have done an upgrade from mvc preview 5 to rc1 recently but my transition to rc1 was flawless without any errors

Only Content Controls are Allowed (C# webcontrols)

断了今生、忘了曾经 提交于 2020-01-02 03:51:07
问题 So, I'm not sure what's going on. My boss wasn't pleased with me using MVC and Razor, so I'm being forced to code with this nasty webcontrol/codebehind style. =/ The error is: Only Content controls are allowed directly in a content page that contains Content controls. Here is the masterpage: <%@ Master Language="C#"%> <!DOCTYPE html> <html> <head> <title>Application Form</title> </head> <body> <div id="container"> <asp:contentplaceholder id="contentPlaceHolder" runat="server" /> </div> </body

How to avoid writing messy JavaScript in an ASP.NET code-behind?

拜拜、爱过 提交于 2020-01-01 14:35:54
问题 I'm questionning about what is the best practice to use Javascript with ASP.NET. I don't know if it's the best practice but I add the javascript client side event inside the codebehind. It is working correctly but is this the best practice? For example, I got a radio button control and I add the Javascript client side event in the Page_Init. The page init can be recalled multiple time so the Javascript will be rendered each time that the Page_It is called. Also, it is hard to debug a long

Alternative to using the OnLoad event in an ASP.Net MVC View?

点点圈 提交于 2020-01-01 07:20:15
问题 I'm creating a simple test application so I can see how ASP.Net MVC works for what we deal with on a daily basis. We use 3rd party controls from Developer's Express, and we will continue to use them. If they absolutely do not work in ASP.Net MVC, then we will not use ASP.Net MVC. With that said, someone has found a way to make it work. He just had to put some code in the code behind. He had to override the OnLoad event and simply just put grid.DataSource = model and grid.DataBind() and it

Can't access GridView event at usercontrol by codebehind

半腔热情 提交于 2019-12-31 07:33:53
问题 IpInterfaceUC UserControl <div id="dvChannel" runat="server"> <asp:GridView ID="gvChannelUC" OnRowCommand="gvChannelUC_RowCommand" OnSelectedIndexChanged="gvChannel_SelectedIndexChanged" /> </div> IPServices page CodeBehind if (!IsPostBack){ }else { string str_btn = Request.Form.Keys[Request.Form.Keys.Count - 1].ToString(); handleClick(str_btn); } Question It always show str_btn is null.If I click Button,It'll show button's id.But when I click Select at GridView,It show str_btn is null.It

C#: How to convert a Website project to a Web Project

拥有回忆 提交于 2019-12-30 03:25:08
问题 UPDATE: All of these problems was for converting a Website application to a Web Project in Visual Studio. Once I dug in and I found the solution, as I marked as answer below. Basically, if you are wanting to upgrade/move your Website project to a Web Project, you will run into a number of errors. The short how-to is in the answer below. Thank you all for comments and help. Old question and title is below: How to wrap namespace xx {} to all class files? How would you wrap namespace to all

How to use asp:image in code behind

馋奶兔 提交于 2019-12-25 18:55:13
问题 I have a problem with rendering asp:image in code behind. First I explain my method: In Default.aspx I just use one label. In code behind I make a string variable and fill it, then I fill the lable.Text by my string variable. this is my Default.aspx : <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server