简体   繁体   English

ASP.NET控件

[英]ASP.NET Controls

Do you use ASP.NET control or just HTML with CSS? 您使用ASP.NET控件还是仅将HTML与CSS一起使用?

I'm having some troubles with width in TextBox and DropDownList. 我在TextBox和DropDownList的宽度方面遇到了一些麻烦。 In different browsers, the width will be different and the controls will not have the same size. 在不同的浏览器中,宽度将不同,并且控件的大小将不同。

I'm considering change this to HTML tag like input and select, but I'm wondering why does ASP.NET has this controls if that they don't work? 我正在考虑将其更改为HTML标签(例如输入和选择),但是我想知道为什么ASP.NET具有此控件,如果它们不起作用? If they don't work, avoid them... right? 如果它们不起作用,请避免它们...对吗?

Give me information I need, make me better than before :-). 给我我需要的信息,使我比以前更好:-)。

Here is the code: 这是代码:

<asp:DropDownList ID="ddlDirComercial" runat="server" CssClass="clsValor" Width="400px">
     <asp:ListItem Text="test" Value="1"></asp:ListItem>
</asp:DropDownList>

<asp:TextBox ID="txtCAE" runat="server" CssClass="clsValor" Width="400px" />

Regards. 问候。

I've used both ASP.NET controls and the HTML input fields as well. 我同时使用了ASP.NET控件和HTML输入字段。 If you look at the source of the page, the TextBox results in an input created on the screen, so either way it wouldn't to use the ASP.NET control since it would be the same anyway. 如果您查看页面的源代码,则TextBox会在屏幕上创建一个输入,因此无论哪种方式都不会使用ASP.NET控件,因为无论如何它都是相同的。 With the control you would have the ability to more easily access code on the server-side. 使用该控件,您将能够更轻松地访问服务器端的代码。 If you have it available to you, I would just stick with the ASP.NET controls 如果您可以使用它,我将坚持使用ASP.NET控件

Those controls can run "on" the server. 这些控件可以在服务器上“运行”。 That's at least one significant reason they exist. 这至少是它们存在的重要原因之一。 They aim to simplify the development of forms by providing a more Windows Forms like development environment. 他们旨在通过提供更多类似于Windows Forms的开发环境来简化表单的开发。

For complex custom ajax driven content I tend to just do it all in javascript and the DOM. 对于复杂的自定义ajax驱动的内容,我倾向于只使用javascript和DOM来完成。

And I agree. 并且我同意。 The controls work. 控制工作。 But maybe not like you would expect. 但也许不像您期望的那样。

Considering that the ASP.NET Controls render into regular HTML, I don't see how you have problems with the ASP.NET Controls width but not the regular width. 考虑到ASP.NET控件呈现为常规HTML,我看不到ASP.NET控件宽度有问题,但常规宽度没有问题。 Of course, I don't use Width and Height properties on ASP.NET controls because I use ASP.NET controls with CSS to set the width and other layout stuff. 当然,我不在ASP.NET控件上使用Width和Height属性,因为我将ASP.NET控件与CSS一起使用来设置宽度和其他布局内容。

Style differences between browsers are common in both server-side and client-side controls, and are far too easily fixed to destroy the advantages of working with ASP.NET controls (such as rapid development, easy data binding, fewer lines of code, etc.). 浏览器之间的样式差异在服务器端和客户端控件中都很常见,并且很容易修复,以至于无法破坏使用ASP.NET控件的优点(例如快速开发,轻松的数据绑定,更少的代码行等) )。 If you find that a straight HTML control looks right, and a server control doesn't, try examining the generated HTML and comparing the two. 如果您发现直接的HTML控件看起来正确而服务器控件则看起来不正确,请尝试检查生成的HTML并将两者进行比较。 The server controls are turned into client-side HTML, so there shouldn't be that much difference. 服务器控件被转换为客户端HTML,因此应该没有太大的区别。

Cross-browser style differences are better solved through CSS than throwing away such a huge feature of ASP.NET. 通过CSS可以更好地解决跨浏览器样式的差异,而不是抛弃ASP.NET的这一巨大功能。 I also understand jQuery is very good for this sort of thing. 我也了解jQuery对于这种事情非常有用。 If you can't get it looking right on your own, you might want to ask someone who specializes in Web design (assuming you have access to one). 如果您自己无法自行解决问题,则可能需要询问专门从事Web设计的人员(假设您可以访问其中的一个)。

Ok guys, I found the problem. 好的,我发现了问题。

The problem isn't in ASP.NET but in input/select behavior with the doctype. 问题不在于ASP.NET,而在于文档类型的输入/选择行为。

As I found here . 我在这里发现。

Thanks to all the answer, they're all good and click ans useful to all. 多亏了所有答案,他们都很好,并单击了对所有人有用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM