This is a migrated thread and some comments may be shown as answers.

literal control not updating

3 Answers 214 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
kyle goodfriend
Top achievements
Rank 2
kyle goodfriend asked on 04 Mar 2011, 01:57 PM
The following code works and updates the literal control perfectly.  When I add the ajax manager, it doesn't update the control at all.  I have tried probably 20 different things.  I have tried the manager, the ajax panel, and cannot get this to work.  If somebody could take a look at this very simple example and tell me what I am doing wrong, I would much appreciate the help.  The literal control should come back with a message - like thank you, email not valid, etc.

Here is the aspx page.
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ajaxsettings>
            <telerik:AjaxSetting AjaxControlID="Button1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Button1"
                        LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="txtEmail" />
                    <telerik:AjaxUpdatedControl ControlID="litStatus" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </ajaxsettings>
    </telerik:RadAjaxManager>
 
    <br />
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    Email: 
    <asp:TextBox ID="txtEmail" runat="server" Width="266px"></asp:TextBox>
    <br />
    <asp:Literal ID="litStatus" runat="server">dddddddd</asp:Literal>
<br />
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server"
    MinDisplayTime="3000" Skin="Default">
</telerik:RadAjaxLoadingPanel>

Here is the code.
Function AddEmail(ByVal strEmail As String) As Boolean
    Me.txtEmail.Text = ""
    Dim inputEmail As String = strEmail.Trim.ToLower
    Dim bSuccess As Boolean = False
    Dim strRegex As String = "^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" & "\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" & ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
    'Validate email
    Dim re As New Regex(strRegex)
    If re.IsMatch(inputEmail) Then
 
    Else
        litStatus.Text = "Please enter a valid email to join our mailing list."
        '            litStatus.Text = "yeah are already a member.  If you are not receiving our communications, please check your spam folder."
        Return (False)
    End If
    'Open file and add email
    Dim xmldoc As New XmlDocument
    xmldoc.Load(Server.MapPath("xmlfile.xml"))
 
    'Check to make sure the email doesn't already exist
    Dim m_nodelist As XmlNodeList = xmldoc.SelectNodes("emails/email")
    For Each m_node In m_nodelist
        Dim strEmailNode = m_node.ChildNodes.Item(0).InnerText.ToString.ToLower
        'Get the lastName Element Value
        If strEmailNode = inputEmail Then
            litStatus.Text = "You are already a member.  If you are not receiving our communications, please check your spam folder."
            Return (False)
        End If
    Next
 
    'Append new node and save xml
    Dim newNode As XmlElement = xmldoc.CreateElement("email")
    newNode.InnerText = inputEmail
    xmldoc.DocumentElement.AppendChild(newNode)
    xmldoc.Save(Server.MapPath("xmlfile.xml"))
    litStatus.Text = "Thank you for joining our mailing list."
    AddEmail = True
End Function


Thank You!

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 08 Mar 2011, 04:48 PM
Hello kyle,

 
There is nothing wrong with your ajax settings. However, a cleaner solution would be to remove the first one and leave the ajax manager as follows:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>                       
                <telerik:AjaxUpdatedControl ControlID="txtEmail" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="litStatus" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>


If the problem persists, could you paste your complete aspx and code-behind using the Code-Formatter tool of the ticket editor.


Best wishes,
Tsvetoslav
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Bryan
Top achievements
Rank 1
answered on 06 Oct 2012, 10:29 PM
Hello I have the same problem.  I have a gridview which has a checkbox template field.  On every databound of the gridview, I loop through the gridview and get the IDs of all of the checkboxes, Using those IDs i add a script block which creates a javascript array of those IDs and adds that to the literal controls' Text Property.  The literal control works the first time, on initial load of the page (Not a postback).  But every subsequent time the grid is bound with new data the literal controls' text property is not updated with the new checkbox IDs, it stays the same as the first time.  I will post my code.  And I am updating the grid using a rad ajax manager.  Also worth noting is that I have also tried using ClientScript.RegisterArrayDeclaration("CheckBoxIDs", checkBoxIDs.ToString) in the databound event with the same 
results as aboive with the literal control.


Thanks

<form id="form1" runat = "server">
    
    <asp:ScriptManager ID = "ScriptManager1" runat = "server"></asp:ScriptManager>
     
    <telerik:RadAjaxManager ID = "RadAjaxManager1" runat = "server" UpdatePanelsRenderMode = "Inline">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID = "grdProjectIssues" EventName = "Sorting">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID = "grdProjectIssues" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
 
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID = "btnFilter1" EventName = "Click">
                <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID = "grdProjectIssues" />
                     <telerik:AjaxUpdatedControl ControlID = "btnAddIssue1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnMailMerge1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnSend1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnForward1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnClose1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnDelete1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnAddIssue2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnMailMerge2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnSend2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnForward2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnClose2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnDelete2" />
                     <telerik:AjaxUpdatedControl ControlID = "pnlNoProjectIssues" />
                     <telerik:AjaxUpdatedControl ControlID = "checkBoxIDsArray" />
                </UpdatedControls>
            </telerik:AjaxSetting>
 
            <telerik:AjaxSetting AjaxControlID = "btnFilter2" EventName = "Click">
                <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID = "grdProjectIssues" />
                     <telerik:AjaxUpdatedControl ControlID = "btnAddIssue1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnMailMerge1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnSend1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnForward1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnClose1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnDelete1" />
                     <telerik:AjaxUpdatedControl ControlID = "btnAddIssue2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnMailMerge2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnSend2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnForward2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnClose2" />
                     <telerik:AjaxUpdatedControl ControlID = "btnDelete2" />
                     <telerik:AjaxUpdatedControl ControlID = "pnlNoProjectIssues" />
                     <telerik:AjaxUpdatedControl ControlID = "checkBoxIDsArray" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
         
 
        <asp:Literal ID = "checkBoxIDsArray" runat = "server"></asp:Literal>



Protected Sub grdProjectIssues_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles grdProjectIssues.DataBound


        Dim checkBoxIDs As New System.Text.StringBuilder


        Dim chkHeader As CheckBox = CType(grdProjectIssues.HeaderRow.FindControl("chkSelectAll"), CheckBox)


        chkHeader.Attributes.Add("onclick", "ChangeAllCheckBoxStates(this.checked);")


        checkBoxIDs.Append("'" & chkHeader.ClientID & "',")


        For Each row As GridViewRow In grdProjectIssues.Rows
            Dim chkBox As CheckBox = CType(row.FindControl("chkSelect"), CheckBox)


            chkBox.Attributes.Add("onclick", "ChangeHeaderAsNeeded();")


            checkBoxIDs.Append("'" & chkBox.ClientID & "',")


        Next


        checkBoxIDs = checkBoxIDs.Remove(checkBoxIDs.Length - 1, 1)


        'ClientScript.RegisterArrayDeclaration("CheckBoxIDs", checkBoxIDs.ToString)


        checkBoxIDsArray.Text = "<script type=""text/javascript"">" & vbCrLf & _
                                "var CheckBoxIDs = new Array(" & checkBoxIDs.ToString & ");" & vbCrLf & _
                                "</script>"


    End Sub
0
Tsvetoslav
Telerik team
answered on 09 Oct 2012, 07:21 AM
Hello Kyle,

The code provided does not supply enough information - your ajax settings seem all right. Please, paste your complete mark-up and code-behind.

Greetings, Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Ajax
Asked by
kyle goodfriend
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or