English 中文(简体)
编码后( c#) 日期时间拾取器的切数值( c#)
原标题:pass the value of datetimepicker to codebehind (c#)

我想将日期时间拾取者的价值传递到我的代码后面( C# ), 并保存到 C# 中的一个变量 。

我用一个隐蔽的场子尝试过 但没用

这里是js代码:

var dates = $("#ArrivalStartDatepicker").datetimepicker({
                            defaultDate: "+lw",
                            dateFormat:  dd-mm-yy ,
                            changeMonth: true,
                            numberOfMonths: 2,
                            ampm: true,
                            stepMinute: 10,
                            minuteGrid: 10,
                            onSelect: function (selectedDate) {
                                    document.getElementById("ArrivalStart").value = dates.datetimepicker( getDate );
                                }
                            });

隐藏字段:

<div>
          <input type="hidden" id="ArrivalStart" runat="server"/> 
</div>

当我选择一个日期或一个时间错误时, 火虫会抛出下列错误 :

文档中,getEplementById (“抵达启动”)为无效

这告诉我,在联署材料中, " 抵达创业 " 战地是无法进入的。

我怎样才能应付?

马非兹

托比

最佳回答

取代

 document.getElementById("ArrivalStart")

使用

  document.getElementById("<%= ArrivalStart.ClientId %>")

这样你就会输入ASP.Net所创建的识别码

EDIT
This javascript fragment needs to be in the aspx file (not a separate js file), as ASP.Net needs to process that <%= .. %> block and needs access to the ArrivalStart member.

问题回答

当您制造一个控件 runat=server时, c# 负责生成该元素。 因此, 大部分时间它会重新写入控件的代号, 因为它需要考虑到控件是何种形式, 而且如果控件嵌入一个数据中继器或其他重复控件中, 也会重新写入该控件的代号 。

如果您运行页面并单击视图源, 元素的代号是否仍然等于 ArrivevalStart, 或者该代号是否被重写?

如果它不正确, 您可以使用 C # 将控件的客户端ID( Control. ClientID) 写入您的 jQuery 脚本

我可能找错人了,





相关问题
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. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签