c# asp.net 控制控件的坐标位置,更改控件坐标,后台改变前台CSS样式,top,left

xiaoxiao2022-12-02  131

前台 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FPSZ.aspx.cs" Inherits="FPSZ" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script language="JavaScript" type="text/javascript" src="../../js/Move.js"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"><div> <div> <asp:Label ID = "lblTKRQText" Text = "黑色头发" runat = "server" name="label" BackColor="Silver" Style="left: 100px; position: relative;top: 200px" Width="104px"></asp:Label> <asp:Label ID = "lblMC" Text = "紫色头发" runat = "server" name="label" BackColor="Silver" Style="left: 300px; position: absolute;top: 240px" Width="113px"></asp:Label> <asp:Label ID="Label3" runat="server">黑色头发的默认坐标值为left:100px; top:200px</asp:Label><br /> <asp:Label ID="Label4" runat="server">紫色头发的默认坐标值为left:300px; top:240px</asp:Label><br /> <asp:Label ID="Label1" runat="server" Text="left的值:"></asp:Label> <asp:TextBox ID="TextBox1" runat="server">200</asp:TextBox> <asp:Label ID="Label2" runat="server" Text="top的值:"></asp:Label> <asp:TextBox ID="TextBox2" runat="server">100</asp:TextBox> </div> <br /> <div>  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="改变黑色头发的位置" /> <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="改变紫色头发的位置" /></div></div> </form></body></html> 后台 using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class FPSZ : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { //lblTKRQText.Style["Style"] = "left: 385px; position: absolute;top:189px";//设置lblTKRQText控件的样式 lblTKRQText.Style["Style"] = "position: relative;top:" + TextBox2.Text + "px;left: " + TextBox1.Text + "px";//设置lblTKRQText控件的样式 } protected void Button2_Click(object sender, EventArgs e) { //lblMC.Style["Style"] = "left: 385px; position: absolute;top:189px";//设置lblMC控件的样式 lblMC.Style["Style"] = "position: absolute;top:" + TextBox2.Text + "px;left: " + TextBox1.Text + "px";//设置lblTKRQText控件的样式 }} 黑色头发:http://heisetoufa.iteye.com/
转载请注明原文地址: https://www.6miu.com/read-4979232.html

最新回复(0)