如何在contentplaceholder中运行javascript函数? [英] how can run javascript function inside contentplaceholder?

查看:95
本文介绍了如何在contentplaceholder中运行javascript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript函数未在contentplace holder中运行





< asp:Content ID =Content6ContentPlaceHolderID =cphIcerikrunat =server>

javascript function not running inside contentplace holder


<asp:Content ID="Content6" ContentPlaceHolderID="cphIcerik" runat="server">

<script type="text/javascript">

      function ValidateDate(sender, args) {
          var selectedDate = sender.get_selectedDate();
          document.getElementById('HiddenField1').value = selectedDate;
          (document.getElementById('dummybtn')).click();
      }
</script>




<asp:TextBox ID="txtdate" runat="server" Width="200px""></asp:TextBox>
                   <asp:ImageButton runat="Server" ID="Image1" ImageUrl="~/images/calendar.png" />
                   <asp:CalendarExtender ID="CalendarExtender1" runat="server"  TargetControlID="txtdate"  PopupButtonID="Image1" OnClientDateSelectionChanged="ValidateDate"></asp:CalendarExtender>
                   <asp:HiddenField ID="HiddenField1" runat="server" />
                   <asp:Button ID="dummybtn" runat="server" Text="Click"  style="display:none" OnClick="dummybtn_Click" />





当我从日历按钮点击事件中选择一天时将运行以及我所知道的选择日期,因为按钮点击事件中还有其他代码,我将使用所选日期。

如果我使用普通的webform< head>< body>等等这个代码运行,因为头部标记内的javascript其他代码在body标签内没有问题。



但是我从masterpage创建了一个母版页和webform,这段代码没有运行。

我觉得javascript函数没有在contentplaceholder里面运行,没有head标签,没有body标签等。



我该怎么办请帮忙。



when I select a day from calender button click event will run and which date selected I know because there is some another codes in button click event and I will use selected date.
if I use normal webform <head><body> etc. this code run because javascript inside head tag other codes inside body tag there is no problem.

but I create a masterpage and webform from masterpage this code not running.
I think javascript function not running inside contentplaceholder there is no head tag there is no body tag etc.

How can I do please help.

推荐答案

如果你在母版页中移动了脚本,也许你的日历没有实例化。



调试:打开开发人员工具,点击控制台。



将你的javascript功能更改为:

Maybe your calendar is not instantiated if you moved the script in the master page.

Debug: Open Developer tools, click on console.

Change your javascript function to:
function ValidateDate(sender, args) {
console.log(sender);
          var selectedDate = sender.get_selectedDate();
console.log(selectedDate);
console.log(document.getElementById('HiddenField1'));
          document.getElementById('HiddenField1').value = selectedDate;

          (document.getElementById('dummybtn')).click();
      }





检查是否有任何未定义的内容(您将立即看到是否通过查看消息来调用该函数控制台)。



Check if anything is undefined (and you'll immediately see if the function is called by seeing the messages in the console).


这篇关于如何在contentplaceholder中运行javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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