locked
Unable to set the value in a Label located inside the user control RRS feed

  • Question

  • User2015884762 posted

    Hi,

    I have got an aspx page with a user control, inside the user control ,there is a repeater and label control. I am actually trying to reload the repeater values, however it was not working, I tried with a label control and that too is not working, I believe something is happening during postback. I am not doing it the right way. This is the code, kindly assist.

    UserControl.aspx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="Bottleneckv1.DenoProfile.WebUserControl1" %>
    
    <!-- Modal -->
    <div id="addModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 id="addModalLabel">Add New Record</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                     	
                </div>
                    
                <asp:UpdatePanel ID="upAdd" runat="server">
                    <ContentTemplate>
                        <table class="table table-bordered table-hover customtable">
                            <tr>
                                <td>NetworkNumber</td>
                                <td>
                                    <asp:TextBox ID="txtFirstNameAdd" runat="server" Width="100%" />
                                    <asp:RequiredFieldValidator ID="valFirstNameAdd" ControlToValidate="txtFirstNameAdd" EnableClientScript="False" Display="Dynamic"
                                        Text="<br />* First Name is required" Font-Bold="true" ForeColor="Red" runat="server"
                                        ValidationGroup="ValidationGroupAdd" /></td>
                                <td>ddf</td>
                            </tr>
                            <tr>
                                <td>OrderDeno</td>
                                <td>
                                    <asp:TextBox ID="txtLastNameAdd" runat="server" Width="100%" />
                                    <asp:RequiredFieldValidator ID="valLastNameAdd" ControlToValidate="txtLastNameAdd" EnableClientScript="False" Display="Dynamic"
                                        Text="<br />* Last Name is required" Font-Bold="true" ForeColor="Red" runat="server"
                                        ValidationGroup="ValidationGroupAdd" /></td>
                                 <td></td>
                            </tr>
                            <tr>
                                <td>OrderCountry</td>
                                <td>
                                    <asp:TextBox ID="txtAddressAdd" runat="server" Width="100%" /></td>
                                 <td></td>
                            </tr>
                            <tr>
                                <td>TotalVolume</td>
                                <td>
                                    <asp:TextBox ID="txtCityAdd" runat="server" Width="100%" /></td>
                                 <td></td>
                            </tr>
                            <tr>
                                <td>SetSize</td>
                                <td>
                                    <asp:TextBox ID="txtRegionAdd" runat="server" Width="100%" /></td>
                                 <td></td>
                            </tr>
                            <tr>
                                <td>MaterialNumber</td>
                                <td>
                                    <asp:TextBox ID="txtPostalCodeAdd" runat="server" Width="100%" /></td>
                                 <td>hf</td>
                            </tr>
    
                            <tr>
                                <td colspan="3" style="text-align: left">ProcessSteps</td>
                            </tr>
                            <tr>
                                
                                <td>
                                    <div style="font-family:Arial, Helvetica, sans-serif;"><u>Instructions</u></div>
                                    <div style="text-align: justify">Sort the Process types in the next column in the right order. A default order has been loaded. You may click the 'x' icon o remove the Process Type from the list. </div>
                                    <div>
                                        <asp:Button ID="loadrpt" runat="server" Text="Reload Default Processes" OnClick="loadrpt_Click"/></div>
                                </td>
                               <td style="text-align: center;vertical-align:middle">
                                   <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                               <ul id="sortable">
            <asp:Repeater runat="server" ID="Repeater1" Visible="true">
        <ItemTemplate>
            <li class="ui-state-default" style="background-color:darkred;color:whitesmoke">
                
                <asp:Label ID="Label2" runat="server" Text=<%# Eval("ProcessTypeName")%> ></asp:Label>
                <img src="../assets/img/window-close-solid.svg" class="closelabelimg" onclick="closelabel(this)" alt="<%# Eval("ProcessTypeName") %>" />
              
     </li>
        </ItemTemplate>
                                                  
    </asp:Repeater>
    
    </ul>
    
                                 
                         </td>
    <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
    
                            </tr>
    
                        </table>
    
                        <div class="modal-footer">
                            <asp:Button ID="btnAddRecord" runat="server" Text="Add" CssClass="btn btn-info" ValidationGroup="ValidationGroupAdd" OnClick="btnAddRecord_Click" />
                            <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
    
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="Gvdenoprofile" EventName="RowCommand" />
                       
                        <asp:AsyncPostBackTrigger ControlID="btnAddRecord" EventName="Click" />
                         <asp:AsyncPostBackTrigger ControlID="loadrpt" EventName="Click" />
                        <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
    
                    </Triggers>
                </asp:UpdatePanel>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->
    

    UserControl.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Bottleneckv1.DenoProfile
    {
       
        public partial class WebUserControl1 : System.Web.UI.UserControl
        {
           
            DataTable dt = new DataTable();
            protected void Page_Load(object sender, EventArgs e)
            {
                this.BindListView();
                /// ScriptManager.RegisterStartupScript(upAdd,this.GetType(),"MyAction", "myFunction()",true);
                if (!this.IsPostBack)
                {
                   
                }
                 else //if page is postback
                    {
                        int i = 0;
                        Label1.Text = i.ToString();
                        Response.Write("hello" + i);
                        i++;
                    this.BindListView();
                }
                
               
            }
    
            private void BindListView()
            {
    
                string ConnectionString = ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString;
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
    
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "SelectAllProcessUnits";
                        cmd.Connection = con;
                        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                        {
                            dt = new DataTable();
                            sda.Fill(dt);
                            Repeater1.DataSource = dt;
                            Repeater1.DataBind();
                            //DenoProfilelv.DataSource = dt;
                            //DenoProfilelv.DataBind();
    
    
                        }
                    }
                }
            }
    
            protected void btnAddRecord_Click(object sender, EventArgs e)
            {
    
            }
    
            protected void loadrpt_Click(object sender, EventArgs e)
            {
                //Repeater1.DataSource = dt;
                //Repeater1.DataBind();
                Label3.Text = "hello";
            }
        }
    }

    Monday, March 8, 2021 9:21 PM

Answers

  • User1535942433 posted

    Hi callykalpana,

    According to your description and codes, I tested and have a problem like this:

    MicrosoftAjaxWebForms.js:6 Uncaught TypeError: Cannot read property 'PRM_ParserErrorDetails' of undefined

    You could press F12 when you run the project and click the "loadrpt" button. And in the panel "Console",you may find something errors.

    You could check your errors.If you have same problems with me,you could use PostBackTrigger on "loadrpt" button.Just like this:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl4.ascx.cs" Inherits="Demo.WebUserControl4" %>
    <div id="addModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 id="addModalLabel">Add New Record</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    
                </div>
                <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <asp:UpdatePanel ID="upAdd" runat="server">
                    <ContentTemplate>
                        <table class="table table-bordered table-hover customtable">
                            <tr>
                                <td>NetworkNumber</td>
                                <td>
                                    <asp:TextBox ID="txtFirstNameAdd" runat="server" Width="100%" />
                                    <asp:RequiredFieldValidator ID="valFirstNameAdd" ControlToValidate="txtFirstNameAdd" EnableClientScript="False" Display="Dynamic"
                                        Text="<br />* First Name is required" Font-Bold="true" ForeColor="Red" runat="server"
                                        ValidationGroup="ValidationGroupAdd" /></td>
                                <td>ddf</td>
                            </tr>
                            <tr>
                                <td>OrderDeno</td>
                                <td>
                                    <asp:TextBox ID="txtLastNameAdd" runat="server" Width="100%" />
                                    <asp:RequiredFieldValidator ID="valLastNameAdd" ControlToValidate="txtLastNameAdd" EnableClientScript="False" Display="Dynamic"
                                        Text="<br />* Last Name is required" Font-Bold="true" ForeColor="Red" runat="server"
                                        ValidationGroup="ValidationGroupAdd" /></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>OrderCountry</td>
                                <td>
                                    <asp:TextBox ID="txtAddressAdd" runat="server" Width="100%" /></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>TotalVolume</td>
                                <td>
                                    <asp:TextBox ID="txtCityAdd" runat="server" Width="100%" /></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>SetSize</td>
                                <td>
                                    <asp:TextBox ID="txtRegionAdd" runat="server" Width="100%" /></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>MaterialNumber</td>
                                <td>
                                    <asp:TextBox ID="txtPostalCodeAdd" runat="server" Width="100%" /></td>
                                <td>hf</td>
                            </tr>
    
                            <tr>
                                <td colspan="3" style="text-align: left">ProcessSteps</td>
                            </tr>upAdd
                            <tr>
    
                                <td>
                                    <div style="font-family: Arial, Helvetica, sans-serif;"><u>Instructions</u></div>
                                    <div style="text-align: justify">Sort the Process types in the next column in the right order. A default order has been loaded. You may click the 'x' icon o remove the Process Type from the list. </div>
                                    <div>
                                        <asp:Button ID="loadrpt" runat="server" Text="Reload Default Processes" OnClick="loadrpt_Click" />
                                    </div>
                                </td>
                                <td style="text-align: center; vertical-align: middle">
                                    <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                                    <ul id="sortable">
                                        <asp:Repeater runat="server" ID="Repeater1" Visible="true">
                                            <ItemTemplate>
                                                <li class="ui-state-default" style="background-color: darkred; color: whitesmoke">
    
                                                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("Total")%>'></asp:Label>
    <%--                                                <img src="../assets/img/window-close-solid.svg" class="closelabelimg" onclick="closelabel(this)" alt="<%# Eval("ProcessTypeName") %>" />--%>
    
                                                </li>
                                            </ItemTemplate>
    
                                        </asp:Repeater>
    
                                    </ul>
    
    
                                </td>
                                <td>
                                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
    
                            </tr>
    
                        </table>
    
                        <div class="modal-footer">
                            <asp:Button ID="btnAddRecord" runat="server" Text="Add" CssClass="btn btn-info" ValidationGroup="ValidationGroupAdd" OnClick="btnAddRecord_Click" />
                            <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
    
                        </div>
                    </ContentTemplate>
                    <Triggers>
                       <%-- <asp:AsyncPostBackTrigger ControlID="Gvdenoprofile" EventName="RowCommand" />--%>
    
                        <asp:AsyncPostBackTrigger ControlID="btnAddRecord" EventName="Click" />
                        <asp:PostBackTrigger ControlID="loadrpt" />
                    <%--    <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />--%>
    
                    </Triggers>
                </asp:UpdatePanel>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    
    public partial class WebUserControl4 : System.Web.UI.UserControl
        {
            DataTable dt = new DataTable();
            protected void Page_Load(object sender, EventArgs e)
            {
                this.BindListView();
                /// ScriptManager.RegisterStartupScript(upAdd,this.GetType(),"MyAction", "myFunction()",true);
                if (!this.IsPostBack)
                {
    
                }
                else //if page is postback
                {
                    int i = 0;
                    Label1.Text = i.ToString();
                    Response.Write("hello" + i);
                    i++;
                    this.BindListView();
                }
            }
            private void BindListView()
            {
    
                string ConnectionString = ConfigurationManager.ConnectionStrings["aspnet-TestApplicationWithDatabase-20190820030542"].ConnectionString;
                using (SqlConnection con = new SqlConnection(ConnectionString))
                {
    
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.CommandText = "select * from Test";
    
                        cmd.Connection = con;
                        using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                        {
                            dt = new DataTable();
                            sda.Fill(dt);
                            Repeater1.DataSource = dt;
                            Repeater1.DataBind();
                            //DenoProfilelv.DataSource = dt;
                            //DenoProfilelv.DataBind();
    
    
                        }
                    }
                }
            }
    
            protected void btnAddRecord_Click(object sender, EventArgs e)
            {
    
            }
    
            protected void loadrpt_Click(object sender, EventArgs e)
            {
                Label3.Text = "hello";
            }
        }
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="2174962.aspx.cs" Inherits="Demo._2174962" %>
    <%@ Register Src="WebUserControl4.ascx" TagName="WebControl" TagPrefix="TWebControl"%>
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <TWebControl:WebControl ID="Header" runat="server" />
            </div>
        </form>
    </body>
    </html>

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 9, 2021 2:31 AM