我怎样才能读取ASP.NET CSS属性? [英] How can I read CSS properties in ASP.NET?

查看:102
本文介绍了我怎样才能读取ASP.NET CSS属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  是否有C#中的CSS解析器?

我想访问在运行时的外部.css文件中定义我的网站的一些CSS属性。我发现,有以编程方式设置在codebehind CSS属性的一种方式,但我还没有碰到过任何方式来读取已定义的人。 (我使用C#)

I'd like to access some CSS properties of my website defined in an external .css file at runtime. I've found that there is a way to programmatically set css properties in the codebehind, but I haven't come across any way to read the ones that are already defined. (I'm using C#)

推荐答案

您可以在运行时只使用客户端脚本阅读。

You can read them "at run time" only using client side script.

使用jQuery它真的很简单,再加上你可以将该值使用AJAX再处理它或将它储存以备后用,然后发送到服务器。

With jQuery it's really simple, plus you can then send the value to the server using AJAX then handle it or store it for later use.

如果它是有效的选项,让我知道,我可以张贴我的意思基本的例子。

If it's valid option let me know and I can post basic example of what I mean.

首先,使用的HTML

First, the HTML used:

<div class="mydiv" id="testDiv">I'm red</div>
<button type="button" id="testButton">Test</button>

CSS:

<style type="text/css">
.mydiv { background-color: red; }
</style>

现在你必须包括jQuery的:

Now you have to include jQuery:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

终于有这个JS code:

And finally have this JS code:

<script type="text/javascript">
$(document).ready(function() {
    $("#testButton").click(function() {
        var oDiv = $("#testDiv");
        var sColor = oDiv.css("background-color");
        $.get("TestZone.aspx?cssvalue=" + sColor);
        alert("value has been sent");
    });
});
</script>

这将发送测试运行时的背景颜色 DIV 到服务器上单击按钮时,在 TestZone.aspx 你可以处理的值。这个例子发送了查询字符串可以同样的方式把它作为POST数据,如果你preFER。

This will send the runtime background color of the test div to the server when the button is clicked, and in the code behind of TestZone.aspx you can handle the value. The example send it over the querystring you can same way send it as POST data if you prefer.

这篇关于我怎样才能读取ASP.NET CSS属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆