locked
dynamically populate control does not work? RRS feed

  • Question

  • User-1647172364 posted

    Hlo Professionals!

    I am executing the dynamic populate control but in output it does not work. I want to get date on button click but its not working. 

    Here Is my code 

    Please execute it.

    Aspx
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm52.aspx.cs" Inherits="WebApplication14.WebForm52" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                 <asp:ScriptManager ID="Script1" runat="server"></asp:ScriptManager>
                <h3>Dynamic Populate</h3>
    
        <asp:Button ID="Button5" runat="server" Text="Get Date" BackColor="Black" ForeColor="#FFCC00" Width="140px" Height="35px" /><br /><br />
        <asp:Label ID="Label2" runat="server" ></asp:Label>
        <ajaxToolkit:DynamicPopulateExtender ID="Label2_DynamicPopulateExtender" runat="server" PopulateTriggerControlID="Button5" ClientIDMode="Static" TargetControlID="Label2" ServiceMethod="GetData" />
    
    
            </div>
        </form>
    </body>
    </html>
    
    C#
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplication14
    {
        public partial class WebForm52 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
    
                }
            }
    
            [System.Web.Script.Services.ScriptMethod()]
            [System.Web.Services.WebMethod]
            public static String GetData()
            {
                return "Today is" + DateTime.Now.ToLongDateString();
            }
    
        }
    }
    
    
    


     

    Friday, July 24, 2020 6:55 AM

All replies

  • User288213138 posted

    Hi sanam13,

    sanam13

    I am executing the dynamic populate control but in output it does not work. I want to get date on button click but its not working. 

    sanam13

    <asp:Button ID="Button5" runat="server" Text="Get Date" BackColor="Black" ForeColor="#FFCC00" Width="140px" Height="35px" /><br /><br />

    This is caused by the postback after the Button is clicked. You can try to use the input button.

     <asp:ScriptManager ID="Script1" runat="server"></asp:ScriptManager>
                <h3>Dynamic Populate</h3>         
                <input id="Button5" type="button" value="Get Date" /><br /><br />
                <asp:Label ID="Label2" runat="server"></asp:Label>
                <ajaxToolkit:DynamicPopulateExtender ID="Label2_DynamicPopulateExtender" runat="server" PopulateTriggerControlID="Button5" ClientIDMode="Static" TargetControlID="Label2" ServiceMethod="GetData" />
    

    The result:

    Best regards,

    Sam

    Friday, July 24, 2020 9:24 AM
  • User-1647172364 posted

    sir this code performs well on other system but in my system it does display output when clicked on button 

    when i clicked on button it displays same as the design in the page like dynamic template with button displays on button clicked 

    sir where is the problem in my code  

    Tuesday, July 28, 2020 9:22 AM
  • User288213138 posted

    Hi sanam13,

    sir this code performs well on other system but in my system it does display output when clicked on button 

    when i clicked on button it displays same as the design in the page like dynamic template with button displays on button clicked 

    Please show me your latest code? 

    Have you encountered any error messages? please try to debug you code.

    Best regards,

    Sam

    Tuesday, July 28, 2020 9:40 AM
  • User-1647172364 posted

    Aspx
    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm53.aspx.cs" Inherits="WebApplication14.WebForm53" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
             <asp:ScriptManager ID="Script1" runat="server"></asp:ScriptManager>
                
           
                <h3>Dynamic Populate</h3>         
                <input id="btn" runat="server" type="button"  value="Get Date" /><br /><br />
                <asp:Label ID="lbl" runat="server"></asp:Label>
                <ajaxToolkit:DynamicPopulateExtender ID="lbl_DynamicPopulateExtender"  runat="server" PopulateTriggerControlID="btn" ClientIDMode="Static"  TargetControlID="lbl" ServiceMethod="GetData" />
    
        </form>
    </body>
    </html>
    
    Cs
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace WebApplication14
    {
    
        public partial class WebForm53 : System.Web.UI.Page
        {
    
            
            protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
    
                }
    
            }
            [System.Web.Script.Services.ScriptMethod()]
            [System.Web.Services.WebMethod]
            public static String GetData()
            {
                return "Today is " + DateTime.Now.ToLongDateString();
            }
    
    
        }
    }

    Tuesday, July 28, 2020 10:16 AM
  • User288213138 posted

    Hi sanam13,

     public static String GetData()
            {
                return "Today is " + DateTime.Now.ToLongDateString();
            }

    I tested your code and it works normally on my side.

    Please set a breakpoint to debug your code, when you click the button, check whether GetData() is triggered.

    Best regards,

    Sam

    Wednesday, July 29, 2020 1:56 AM