Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, when adding a JQuery UI Datepicker to my generated textBox control,it is working but whatever I am adding an UpdatePanel it is not working I dont know why...

Javascript:
XML
<script type="text/javascript">
         $(function () {
             $(".myDates").datepicker();
         });
      </script>

HTML:
ASP.NET
<div id="myForm" runat="server">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Panel ID="pnlUserName" runat="server">
                    <fieldset class="fieldset">
                        <legend class="legend">Product Info</legend>

                        <div id="textBoxGenerated" runat="server">
                            <asp:TextBox ID="txtseachUserName" runat="server" required="required" class="search autosuggest"></asp:TextBox>
                            <asp:Button ID="btnsearch" runat="server" Text="Search" class="Buttom" OnClick="btnsearch_Click" /><br />
               </div>
                   </fieldset>
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>


protected void btnsearch_Click(object sender, EventArgs e)
    {
        int number = Convert.ToInt32(txtseachUserName.Text);
        string top = "";
        int left = 0;
        TextBox txt;
        Table tb = new Table();
        tb.ID = "tb1";
        TableRow tr = new TableRow();
        for (int i = 1; i <= number; i++)
        {
            Label lb = new Label();
            lb.ID = "lbFname" + i.ToString();
            lb.Text = "Date" + i + ":";

            Literal l = new Literal();
            l.Text = "<br/>";

            txt = new TextBox();
            txt.ID = "textBox" + i.ToString();//this will add the current number to textBox means textBox1, textBox2, textBox3 etc...
            txt.Attributes.Add("runat", "server");

            //txt.Attributes.Add("onkeyup", "SetButtonStatus(this,'btnSave')");
            txt.CssClass = "myDates";
            txt.Width = Unit.Pixel(240);
            txt.Style.Add(HtmlTextWriterStyle.MarginTop, "5px");
            txt.MaxLength = 1;
            txt.EnableViewState = true;
            txt.Style.Add(HtmlTextWriterStyle.Position, "relative");
            //txt.Style[HtmlTextWriterStyle.Top] = top + "px";
            txt.Style[HtmlTextWriterStyle.Left] = left + "px";
            left += 0;

            textBoxGenerated.Controls.Add(lb);
            textBoxGenerated.Controls.Add(txt);
            textBoxGenerated.Controls.Add(l);
        }

can someone help!
Posted
Updated 10-Sep-13 1:43am
v2
Comments
VICK 11-Sep-13 1:30am    
Have you used scriptmanager along with update panel on the page and AsyncPostBackTrigger...???

 
Share this answer
 
Comments
El Dev 10-Sep-13 8:57am    
Hi, I have tried using the link but is it is not working...
Since it is dynamically generated and its in update panel jquery is unable to bind that event to that control. You'll have to use delegate() function of jquery to bind jquery event to dynamic controls.

alternatively you can add your script block inside update panel.
 
Share this answer
 
Comments
El Dev 10-Sep-13 9:09am    
please can u show me by using my code, I have never used the delegate function.
This how I am using inside my code:
<script type="text/javascript">
$(function () {
$(".myDates").delegate(function () {
$(this).datepicker();
});
});
</script>
I dont know if it is like that but it is not workin also,I have even tried to use the script block inside update panel.Please help on that...
just you need to add this javascript

XML
<script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (evt, args) {
            $(".DatePicker").datepicker({
                dateFormat: 'dd-mm-yy'
            });
        });
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900