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

[Solved] $find when using Ajax Manager coming back null?

1 Answer 86 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 13 Jun 2009, 04:18 PM

I have a radContextMenu inside an ajax manager (i have also tried an updatePanel too) and when  I try to fire the $find after an ajax postback I get a script error that the menu is null. Here is my code (i am not including hte declarations):

<asp:Content ID="Content2" ContentPlaceHolderID="pageContent" Runat="Server">  
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnSearch">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="tbCityStateZip" /> 
                    <telerik:AjaxUpdatedControl ControlID="rdMenuNarrowSearch" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
<script type="text/javascript">  
        function showMenu() {  
            var contextMenu = $find("<%#rdMenuNarrowSearch.ClientID %>");  
 
            var xy = findPos(document.getElementById('<%#Me.tbCityStateZip.ClientID %>'));  
 
            contextMenu.showAt(xy[0], xy[1]);  
 
        }  
 
 
        function findPos(obj) {  
            var curleft = curtop = 0;  
            if (obj.offsetParent) {  
                do {  
                    curleft += obj.offsetLeft;  
                    curtop += obj.offsetTop;  
 
                } while (objobj = obj.offsetParent);  
 
 
                return [curleft, curtop];  
            }  
        }  
         
         
    </script> 
      
    <div style="width: 410px; height: 300px; background: #f3f7fe; margin-top: 10px; float: left;">  
    <div style="padding-top: 10px; padding-left: 10px;  width: 375px; "<span style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 24px; font-weight: bold; color: #6684b3; padding-left: 3px;">Property Search</span> 
      <hr style="height: 0; border: 0; border-top: 1px solid #069; margin-top: 2px; "/>  
    </div> 
    <div style="padding-left: 10px;">  
      <table width="375" border="0" cellspacing="0" cellpadding="0" > 
        <tr> 
          <td colspan="2"><span class="propertySearchHeadings"> City &amp; State or Zip  
              </span> 
              <br /> 
              <asp:TextBox   
                  ID="tbCityStateZip" runat="server" Width="362px" CssClass="textBoxes"></asp:TextBox> 
              </td> 
        </tr> 
        <tr> 
          <td width="50%"><span class="propertySearchHeadings">Price</span> 
          <br /> 
              <asp:DropDownList ID="DropDownList1" runat="server" Width="175px" CssClass="dropDowns">  
              <asp:ListItem Text=" -- Any Price --" Value="0">            
              </asp:ListItem> 
              <asp:ListItem Text="< $50,000" Value="< 50000">            
              </asp:ListItem> 
              <asp:ListItem Text="$50,000 - $100,000" Value="50000 - 100000">            
              </asp:ListItem> 
              <asp:ListItem Text="$100,000 - $150,000" Value="100000 - 150000">            
              </asp:ListItem> 
              <asp:ListItem Text="$150,000 - $200,000" Value="150000 - 200000">            
              </asp:ListItem> 
              <asp:ListItem Text="$200,000 - $250,000" Value="200000 - 250000">            
              </asp:ListItem> 
              <asp:ListItem Text="$250,000 - $300,000" Value="250000 - 300000">            
              </asp:ListItem> 
              <asp:ListItem Text="$300,000 - $350,000" Value="300000 - 350000">            
              </asp:ListItem> 
              <asp:ListItem Text="$350,000 - $400,000" Value="350000 - 400000">   
              </asp:ListItem> 
              <asp:ListItem Text="$400,000 - $450,000" Value="400000 - 450000">            
              </asp:ListItem> 
              <asp:ListItem Text="$450,000 - $500,000" Value="450000 - 500000">            
              </asp:ListItem> 
              <asp:ListItem Text="$500,000 - $550,000" Value="500000 - 550000">            
              </asp:ListItem> 
              <asp:ListItem Text="> $550,000" Value="> 550000">            
              </asp:ListItem> 
              </asp:DropDownList> 
          </td> 
          <td width="50%"><span class="propertySearchHeadings">Beds</span> 
          <br /> 
          <asp:DropDownList ID="DropDownList2" runat="server" Width="175px" CssClass="dropDowns">  
              <asp:ListItem Text=" -- Any Beds --" Value="0">            
              </asp:ListItem> 
              <asp:ListItem Text="1" Value="1">            
              </asp:ListItem> 
              <asp:ListItem Text="2" Value="2">            
              </asp:ListItem> 
              <asp:ListItem Text="3" Value="3">            
              </asp:ListItem> 
              <asp:ListItem Text="4" Value="4">            
              </asp:ListItem> 
              <asp:ListItem Text="5" Value="5">            
              </asp:ListItem> 
              <asp:ListItem Text="6" Value="6">            
              </asp:ListItem> 
              <asp:ListItem Text="7" Value="7">            
              </asp:ListItem> 
              <asp:ListItem Text="8" Value="8">            
              </asp:ListItem> 
              <asp:ListItem Text="9" Value="9">            
              </asp:ListItem> 
              <asp:ListItem Text="10" Value="10">            
              </asp:ListItem> 
              <asp:ListItem Text="> 10" Value="> 10">            
              </asp:ListItem> 
                
              </asp:DropDownList> 
          </td> 
        </tr> 
        <tr> 
          <td><span class="propertySearchHeadings">Baths</span> 
          <br /> 
          <asp:DropDownList ID="DropDownList3" runat="server" Width="175px" CssClass="dropDowns">  
              <asp:ListItem Text=" -- Any Baths --" Value="0">            
              </asp:ListItem> 
              <asp:ListItem Text="1" Value="1">            
              </asp:ListItem> 
              <asp:ListItem Text="1.5" Value="1.5">            
              </asp:ListItem> 
              <asp:ListItem Text="2" Value="2">            
              </asp:ListItem> 
              <asp:ListItem Text="2.5" Value="2.5">            
              </asp:ListItem> 
              <asp:ListItem Text="3" Value="3">            
              </asp:ListItem> 
              <asp:ListItem Text="3.5" Value="3.5">            
              </asp:ListItem> 
              <asp:ListItem Text="4" Value="4">            
              </asp:ListItem> 
              <asp:ListItem Text="4.5" Value="4.5">            
              </asp:ListItem> 
              <asp:ListItem Text="5" Value="5">            
              </asp:ListItem> 
              <asp:ListItem Text="5.5" Value="5.5">            
              </asp:ListItem> 
              <asp:ListItem Text="6" Value="6">            
              </asp:ListItem> 
              <asp:ListItem Text="6.5" Value="6.5">            
              </asp:ListItem> 
                
              </asp:DropDownList> 
          </td> 
          <td>&nbsp;</td> 
        </tr> 
        <tr> 
          <td colspan="2" align="center">  
              <br /> 
          <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="~/images/UserAccount/buttons/btn_Search.png" /> 
              </td> 
        </tr> 
      </table> 
    </div> 
  </div> 
  <div style="width: 410px; height: 300px; background: #f3f7fe; margin-top: 10px; float: right;">  
    <div style="padding-top: 10px; padding-left: 10px;  width: 375px; "<span style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 24px; font-weight: bold; color: #6684b3; padding-left: 3px;">Find SpinStitch On:</span> 
      <hr style="height: 0; border: 0; border-top: 1px solid #069; margin-top: 2px; "/>  
    </div> 
  </div> 
  <telerik:RadContextMenu ID="rdMenuNarrowSearch" runat="server" Skin="Office2007">  
    <Items> 
        <telerik:RadMenuItem Text="Narrow Search" Enabled="false"></telerik:RadMenuItem> 
    </Items> 
    </telerik:RadContextMenu> 
    
  <%--<div style="padding-top: 25px; clear: both"/>  
  <div style="clear: both; width: 900px; height: 29px; background:url(images/SSToursHeading/backgroundMenuBar.jpg);  "<span style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size: 24px; font-weight: bold; color: #036; padding-left: 12px;">Recent Tours</span> </div>--%> 
<asp:RequiredFieldValidator ID="valCityStateZip" runat="server" ErrorMessage="Please Enter A City & State or Zip Code." 
            SetFocusOnError="true" ControlToValidate="tbCityStateZip" Display="None"></asp:RequiredFieldValidator> 
        <cc1:ValidatorCalloutExtender ID="valEXCityStateZip" runat="server" TargetControlID="valCityStateZip">  
        </cc1:ValidatorCalloutExtender> 
          
      
</asp:Content> 

Code behind:
Partial Class PropertySearch  
        Inherits System.Web.UI.Page  
        Private _city As String = String.Empty  
        Private _state As String = String.Empty  
        Private _zipCode As String = String.Empty  
        Private _stateSet As DataSet = Nothing 
        Protected Sub btnSearch_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSearch.Click  
            If Not _stateSet Is Nothing AndAlso Not _stateSet.Tables Is Nothing AndAlso _stateSet.Tables(0).Rows.Count > 1 Then 
                For Each zipRow As DataRow In _stateSet.Tables(0).Rows  
                    Dim contextMenuItem As New Telerik.Web.UI.RadMenuItem  
                    contextMenuItem.Text = zipRow("CITY") & ", " & zipRow("ABBR")  
                    contextMenuItem.ToolTip = zipRow("CITY") & ", " & zipRow("ABBR")  
                    Me.rdMenuNarrowSearch.Items.Add(contextMenuItem)  
                Next 
 
 
                ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType"showContextMenu""showMenu();"True)  
            End If 
        End Sub 
 
          
         
    End Class 

If I take the menu out of an updatePanel or ajax manager, the menu will show, but does not get updated. Any thoughts?

Daniel

1 Answer, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 14 Jun 2009, 02:23 PM

I should have realized what the issue was, but the problem was with how the script block was beign written to the page after postback. I repalced: 
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType, "showContextMenu", "showMenu();", True)

Repalced with:
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.Page.GetType, "showContextMenu", " Sys.Application.add_load(function(){

 

 

 

showMenu();});", True)

Daniel

Tags
Menu
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Share this question
or