Date Picker in Asp.net doesn’t appear.

huangapple go评论48阅读模式
英文:

Date Picker in Asp.net doesn't appear

问题

我创建了2个日期选择器,但只有1个在运行时显示日期表格。

<div class="form-group left">
    <label for="invoicedate" class="label-title"> Invoice Date : </label>
    <asp:TextBox ID="txtDate" runat="server" class="form-input" required="required" ReadOnly="true" placeholder="mm/dd/yyyy" OnClick="Datebtn_Click"></asp:TextBox>
</div>
<div class="form-group left">
    <label for="shipmentdate" class="label-title"> Shipment Date : </label>
    <asp:TextBox ID="textDate" runat="server" class="form-input" required="required" ReadOnly="true" placeholder="mm/dd/yyyy" OnClick="Addbtn_Click"></asp:TextBox>
</div>

代码部分:

protected void Datebtn_Click(object sender, EventArgs e)
{
    string dt = Request.Form[txtDate.UniqueID];
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected Date:" + dt + "'); ", true);
}

protected void Addbtn_Click(object sender, EventArgs e)
{
    string dt = Request.Form[txtDate.UniqueID];
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected Date:" + dt + "'); ", true);
}

脚本代码:

<script type="text/javascript">
    $(function () {
        $('[id*=txtDate]').datepicker({
            changeMonth: true,
            changeYear: true,
            format: "dd/mm/yyyy",
            language: "tr"
        });
    });
</script>

当我运行它时,没有显示任何错误。有人能帮助我吗?

英文:

I make 2 datepicker but only 1 show the table of date when I run it

&lt;div class=&quot;form-group left&quot;&gt;
                                &lt;label for=&quot;invoicedate&quot; class=&quot;label-title&quot;&gt; Invoice Date : &lt;/label&gt;
                                &lt;asp:TextBox ID=&quot;txtDate&quot; runat=&quot;server&quot; class=&quot;form-input&quot; required=&quot;required&quot; ReadOnly=&quot;true&quot;  placeholder=&quot;mm/dd/yyyy&quot; OnClick=&quot;Datebtn_Click&quot;&gt;&lt;/asp:TextBox&gt;
                            &lt;/div&gt;
&lt;div class=&quot;form-group left&quot;&gt;
                                &lt;label for=&quot;shipmentdate&quot; class=&quot;label-title&quot;&gt; Shipment Date : &lt;/label&gt;
                                 &lt;asp:TextBox ID=&quot;textDate&quot; runat=&quot;server&quot; class=&quot;form-input&quot; required=&quot;required&quot; ReadOnly=&quot;true&quot;  placeholder=&quot;mm/dd/yyyy&quot; OnClick=&quot;Addbtn_Click&quot;&gt;&lt;/asp:TextBox&gt;
                            &lt;/div&gt;

The code behind

protected void Datebtn_Click(object sender, EventArgs e)
        {
            string dt = Request.Form[txtDate.UniqueID];
            ClientScript.RegisterStartupScript(this.GetType(), &quot;alert&quot;, &quot;alert(&#39;Selected Date:&quot; + dt + &quot;&#39;); &quot;, true);
        }

        protected void Addbtn_Click(object sender, EventArgs e)
        {
            string dt = Request.Form[txtDate.UniqueID];
            ClientScript.RegisterStartupScript(this.GetType(), &quot;alert&quot;, &quot;alert(&#39;Selected Date:&quot; + dt + &quot;&#39;); &quot;, true);
        }

Script code

&lt;script type=&quot;text/javascript&quot;&gt;
    $(function () {
        $(&#39;[id*=txtDate]&#39;).datepicker({
            changeMonth: true,
            changeYear: true,
            format: &quot;dd/mm/yyyy&quot;,
            language: &quot;tr&quot;
        });
    });
&lt;/script&gt;

It doesn't show any error when I run it. Can anyone help me

答案1

得分: 0

因为您创建了两个具有不同Id的文本框,一个是"txtDate",另一个是"textDate"。

对于Addbtn_Click:id 应更改为:"textDate.UniqueID"。

脚本中只有txtDate。

在进行所有相应的修改之后,两者都应该能够正常工作。

英文:

Because you created two textboxes with different Ids, one with "txtDate" and another with "textDate".

For Addbtn_Click: id should be changed to: "textDate.UniqueID"

There is only txtDate in the script.

After all corresponding modifications are made, then both should be able to work.

huangapple
  • 本文由 发表于 2023年2月16日 14:07:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定