ASP.NET:将服务器控件与客户端控件混合在一起吗? [英] ASP.NET: Mixing server controls with client controls?

查看:67
本文介绍了ASP.NET:将服务器控件与客户端控件混合在一起吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙吗?

我通常使用服务器控件,即文本框,以便可以访问服务器端事件.

I normally use server controls i.e Textbox so i can get access to the server side event.

但是如果我不需要访问服务器端事件,并且例如要在文本框中放置一些jquery或javascript,该怎么办?

But what if i don't need access to the server side event and i am going to place some jquery or javascript on the textbox for example.

我可以使用标准的HTML(客户端控件)吗?

Can i use a standard HTML (client controls) ?

这是好习惯吗?

预先感谢

推荐答案

如果您要访问ASP.NET中的控件值,则可以使用简单的HTML标准控件BUT,那么您将不得不添加runat ="server标签",请参见下方

YOu can use simple HTML standard control BUT if you want to access that controls value in ASP.NET then you will have to add runat="server tag" see below

<input type="text" runat="server" id="mytxtbox" name="mytxtbox">

如果您确实要使用HTML控件,则可以使用它们.但是,如果您想在服务器端访问标准ASP.NET控件,则可以轻松使用标准ASP.NET控件.

If you really want to use HTML controls you can use them. but it will make your life easy to use standard ASP.NET controls if you are trying to access them on server side.

如果您也想使用javascript访问这些控件,则可以使用类似的

And if you want to access those controls using javascript as well then you can use something like

var mytxtele = document.getElementById('<%= mytxtbox.ClientID %>')

这就是您如何获取文本框元素并在javascript中进行播放的方法.

thats how you can get textbox element and play with it in javascript.

上面的代码是一个基本概念,取决于您希望它如何工作

This above code is a basic idea, depends how you want it to work

这篇关于ASP.NET:将服务器控件与客户端控件混合在一起吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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