code-behind

Adding css class through aspx code behind

落爺英雄遲暮 提交于 2019-11-28 06:41:20
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? 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") If you're not using the id for anything other than code-behind reference (since .net mangles the ids), you could use a panel control and reference it in your codebehind: <asp:panel runat="server" id="classMe"></asp

Custom attributes in ASP.NET web forms HTML tag

佐手、 提交于 2019-11-28 05:09:26
问题 I am using ASP.NET webforms on the .NET 3.5 framework. How can I achieve a custom attribute in the HTML tag such as: <HTML lang="en"> I want to achieve this in the code behind on a common inherited base page. The attribute value would dynamically set based on a session value everytime a page is loaded. Late addition: I want to achieve this without any ASP page changes to script tags if possible 回答1: The suggested solution: <HTML lang="<%= PageLanguage %>"> works fine. There's another

How to I access an attached property in code behind?

时光毁灭记忆、已成空白 提交于 2019-11-28 04:48:10
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, KeyEventArgs e) { theObject.Canvas.Left = 50; } Does anyone know what the syntax is to do this? AnthonyWJones

how to have one of the column in gridview to be an image?

╄→гoц情女王★ 提交于 2019-11-28 04:13:55
问题 I have a gridview that gets created in codebehind. In the below code, I would like to have 3rd column to be some image (Example: PDF icon or similar). I am thinking Type.GetType needs to be changed for column named "Image"?? DataTable dt = new DataTable(); GridView gview = new GridView(); DataRow dr; DataColumn dc = new DataColumn("Description", Type.GetType("System.String")); dt.Columns.Add(dc); dc = new DataColumn("Image", Type.GetType("System.String")); dt.Columns.Add(dc); dc = new

How to programmatically measure string pixel width in ASP.NET?

南楼画角 提交于 2019-11-28 03:14:42
问题 How do you get the size of a string? In Windows Forms it's easy, I just use graphics object and then MeasureString function. In ASP.NET I'm not sure how to do this. 回答1: Like Tom Gullen is saying. You can just create a bitmap and messure the string. I have this code I use to find the width/length in pixel. Just change the font and size. // Bitmap class namespace: using System.Drawing; ... private float GetWidthOfString(string str) { Bitmap objBitmap = default(Bitmap); Graphics objGraphics =

C# code behind for Button Click Event, ASP.NET

試著忘記壹切 提交于 2019-11-28 01:17:10
问题 I'm working with HTML provided by coworker in .aspx and I need to program in .aspx.cs(C#) the functionality of the button he created using HTML. The code I'm dealing with is as follows: </div> <button style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue">Ship</button> <button style="padding: 10px; margin-bottom: 10px;" class="w3-round w3-blue">Rate</button> </div> I'm new to HTML but in looking at solutions to similar questions I often see the HTML code for a functional button

Redirect to another page using Post method from Code behind

做~自己de王妃 提交于 2019-11-27 22:45:23
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 Asad Butt string url = "3rd Party Url"; StringBuilder postData = new StringBuilder(); postData.Append("first_name=" + HttpUtility.UrlEncode(txtFirstName.Text) + "&");

Parser Error: Server Error in '/' Application

放肆的年华 提交于 2019-11-27 21:01: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#" %> Right-click your Global.asax file and click View Markup . You will see the attribute Inherits="nadeem.MvcApplication" . This means that your Global.asax file is trying to inherit from the type nadeem

ASP.net page without a code behind

假如想象 提交于 2019-11-27 20:23:57
问题 I have an ASP.Net page with a C# code behind. However, I've been asked to not use a code behind - so that it will be easier to deploy in SharePoint. Is there a way to include the C# code in the ASP.Net page, without using a separate code behind file? 回答1: By default Sharepoint does not allow server-side code to be executed in ASPX files. See this for how to resolve that. However, I would raise that having a code-behind is not necessarily difficult to deploy in Sharepoint (we do it extensively

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

梦想与她 提交于 2019-11-27 19:50:16
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?? Andrew Harry 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.ascx.cs ) Add using System.Web.Mvc; to the class Change the class to Inherit from