English 中文(简体)
贾瓦特在Html服务器控制方面赢得了笔工作?
原标题:Javascript won t work on Html server control?

我正在撰写一个网站。 ASP. 净额

我将有很多<代码>html通用控制,如<div> <span>等。

我有<代码>onclickjavascript functions,onmouseover javascript function.

他们正在做罚款。

然后,我需要控制服务器一侧。

因此,我添加<代码>runat=“server”。

之后,所有 j都是徒劳的。

我的理解是,他们只是工作团队,现在所有活动都回到服务器上。

因此,他们的工作是否有任何途径?

For eg,

<div id="myDiv1" onclick="myfunction(para1)"><img src="..." /></div>

上述法典正在发挥作用。

<div id="myDiv1" runat="server" onclick="myfunction(para1)"><img src="..." /></div>

上述法典没有发挥作用......

我可以做到这一点,或许可以做到这一点。

<div id="externalDiv1" onclick="myfunction(para1)"><div id="myDiv1" runat="server" ><img src="..." /></div></div>

是否有其他办法?

最佳回答

服务器方或客户方方控制在单方控制方面没有任何差别。 所有服务器对面的控制最终成为正常的超文本控制。 如果你的 j印功能不可行,是因为你通过提供服务器的侧面控制来获取这些功能,他们现在可以带上像<条码>和代号”、“父母——id>_< Control_id>等模式的ids。

例如,宣布的跨段内容类似:

<span id="mylabel" runat="server"> testing</span>

最终可以:

<span id="MainContent_mylabel"> testing</span>

ASP.NET 4.0有一个称为的特征 CliendIDMode which can be set to >>> static ,意思是,贵重标上的ids将在该页后保持不变。

问题回答

I assume that you used document.getElementById() to get an element by its id. If you are using master pages, the IDs of server controls will be changed after rendering to the page, in that case, you have to use its ClientID for e.g.

var myDiv1 = document.getElementById("<%= myDiv1.ClientID %>");




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签