使用母版页时的javascript [英] javascript when masterpage is used

查看:116
本文介绍了使用母版页时的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用过.js文件和.js文件我已经使javascript.i使用了masterpage来制作form.now在这种形式我想申请javascript.then链接...

i have used .js file and in .js file i have made javascript.i have used masterpage to make form.now in this form i want to apply javascript.then link ...

<script src="javascript/TextboxValidation.js" type="text/javascript"></script>



我要放的地方?。i已经放了这个在我在下面显示的mastrpage中,但它不起作用。


where i have to put?.i have put this in mastrpage which i have shown below,but it is not working.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

    <script src="javascript/JScript1.js" type="text/javascript"></script>
    <script src="javascript/print.js" type="text/javascript"></script>
    <script src="javascript/TextboxValidation.js" type="text/javascript"></script>

推荐答案

问题

如果在渲染过程中使用母版页,内容页面中存在的控件ID将会更改。



为您的文本框

Problem
The ID of controls present in the content page will be changed if master page is used during rendering.

For your textbox
<asp:TextBox ID="txt_TotalFees" runat="server" Width="200px" onblur="SurName()" Enabled="false">



Th e id txt_TotalFees 将变为类似''ctl00_ContentPlaceHolder1_txt_TotalFees''(不完全一样)。



您可以通过在浏览器中查看网页来源来看到这一点。



解决方案

1. ClientID ,如果你在内容aspx页面(不是你的情况)写这个。


The id txt_TotalFees will become something like ''ctl00_ContentPlaceHolder1_txt_TotalFees'' (not exact).

You can see this by viewing the source of the webpage in the browser.

Solutions
1. ClientID, if you are writing this in content aspx page (not your case).

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



它不会在外部js文件中工作。



2. 在aspx文件中声明一个全局js变量并将其设置为ClientID值。现在在外部文件中你可以在这个var上使用getElementById。

参考 - 如何在外部javascript文件中获取客户端ID [ ^ ]



2. ClientIDMode.Static 尝试这个

你可以使用这个。只需将此属性添加到文本框中,如下所示。


It will not work in External js file.

2. Declare a global js variable in the aspx file and set it to the ClientID value. Now in the external is file you can use getElementById on this var.
Refer - How to get client id at external javascript file[^]

2. ClientIDMode.Static (try this one)
You can use this one. Just add this attribute to the textbox like below.

<asp:TextBox ID="txt_TotalFees" runat="server" Width="200px" onblur="SurName()" Enabled="false" ClientIDMode="Static">



因此,在浏览器中渲染后,ID将与 txt_TotalFees 相同。



然后,外部js中的以下行将起作用。


So, after rendering in browser the ID will be the same as txt_TotalFees.

Then, the below line in External js will work.

var x = document.getElementById("txt_TotalFees");



要了解有关ClientIDMode的更多信息,请参阅 - ASP.NET 4.0:使用ClientIDMode操纵ClientID [ ^ ]

尝试这个解决方案并告诉我。



Th anks ...


To know more about the ClientIDMode refer - ASP.NET 4.0 : Manipulate ClientID using ClientIDMode[^]
Try this solution and let me know.

Thanks...


HI,



确保已将以下文件添加到巡视母版页。





Make sure that you have added the following file to tour master page.

<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>



在主页面中添加此项,然后在控件存在的页面中添加以下代码。




Add this in the master page and then the following bunch of code in the page where the control present.

function SurName() { var x =


(#txt_TotalFees); x.value = x.value.toUpperCase(); }
("#txt_TotalFees"); x.value = x.value.toUpperCase(); }





这是了解脚本页面所必需的。



谢谢



This is needed to know the page about the scripts.

Thanks


这篇关于使用母版页时的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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