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

RadAjaxManager1.ClientID returning null

4 Answers 287 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Suresh
Top achievements
Rank 1
Suresh asked on 17 Jul 2008, 08:06 PM
Hi,

 I using Vs2008/3.5 framework and creating new web application and when  i tested a Telerik example code in that solutions,i'm getting a script error that RadAjaxManager is null when i use the following code.

  $find(

"<%= RadAjaxManager1.ClientID %>").ajaxRequest();

even i replaced web.config with Telerik example web.config.still i m getting error. 

what could be the reason?

4 Answers, 1 is accepted

Sort by
0
Suresh
Top achievements
Rank 1
answered on 17 Jul 2008, 09:19 PM
Ok I solved that issue by placing the script tag between body and html. But now i'm facing Ajax manager to post back the page fully.  here is my code for your reference,

 

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>

<%

@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

 

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

 

<title>Untitled Page</title>

 

 

</

head>

<

body>

 

<form id="form1" runat="server">

 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">

 

</telerik:RadScriptManager>

 

<div>

 

<asp:Button ID="Button1" runat="server" Text="Using AjaxManager"

onclick="Button1_Click" />

 

<asp:TextBox ID="TextBox1"

 

runat="server"></asp:TextBox>

 

<asp:Button ID="Button3" runat="server" OnClientClick="javascript:callAjax()"

Text="Call AjaxRequest through Javascript Function" />

 

</div>

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">

 

<AjaxSettings>

 

<telerik:AjaxSetting AjaxControlID="Button1">

 

<UpdatedControls>

 

<telerik:AjaxUpdatedControl ControlID="TextBox1" />

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

</UpdatedControls>

 

</telerik:AjaxSetting>

 

<telerik:AjaxSetting AjaxControlID="Button2">

 

<UpdatedControls>

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" />

 

</UpdatedControls>

 

</telerik:AjaxSetting>

 

</AjaxSettings>

 

</telerik:RadAjaxManager>

 

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="AccessDataSource1"

GridLines="None">

<

MasterTableView DataSourceID="AccessDataSource1">

<

RowIndicatorColumn>

<

HeaderStyle Width="20px"></HeaderStyle>

</

RowIndicatorColumn>

<

ExpandCollapseColumn>

<

HeaderStyle Width="20px"></HeaderStyle>

</

ExpandCollapseColumn>

</

MasterTableView>

 

</telerik:RadGrid>

 

<asp:AccessDataSource DataFile="~/App_Data/Nwind.mdb" ID="AccessDataSource1" runat="server"

 

SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees]">

 

</asp:AccessDataSource>

 

<asp:Button ID="Button4" runat="server" Text="Post back the page"

onclick="Button4_Click" />

 

</form>

</

body>

 

<script language="javascript" type="text/javascript">

 

function callAjax()

{

$find(

"<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");

}

</script>

</

html>



and in the code behind, 

using

System;
using System.Data;
using System.Web.UI;
using Telerik.Web.UI;
namespace WebApplication6
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (Page.IsPostBack)
{

TextBox1.Text =

"NotPostBack";

}

}

protected void Button1_Click(object sender, EventArgs e)

{

TextBox1.Text =

"NotPostBack";

BindGrid();

}

private void BindGrid()

{

DataTable dt = new DataTable();

dt.Columns.Add(

"Account");

dt.Columns.Add(

"AccountNO");

DataRow dr = dt.NewRow();

dr[

"Account"] = "Account1";

dr[

"AccountNO"] = "123456";

dt.Rows.Add(dr);

RadGrid1.DataSource =

null;

RadGrid1.DataSourceID =

null;

RadGrid1.DataSource = dt.DefaultView;

RadGrid1.Rebind();

}

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)

{

BindGrid();

}

protected void Button3_Click(object sender, EventArgs e)

{

BindGrid();

}

protected void Button4_Click(object sender, EventArgs e)

{

TextBox1.Text =

"PostBack";

}

}

}

0
Lyle Groome
Top achievements
Rank 2
answered on 17 Jul 2008, 09:50 PM
Suresh, Just noticing your post and I've bumped into a problem myself with something I noticed in your code. This may not be your actual issue, but I think I see an issue in your code with the button event. On your asp:Button id=Button3 you have a client event that it is trying to call that calls ajax, but you don't cancel the actual server click event that will trigger a postback.  

<asp:Button ID="Button3" runat="server" OnClientClick="javascript:callAjax()" Text="Call AjaxRequest through Javascript Function" /> 

Try adding return false; to the onclientclick (see below). The reason is that if you click that button right now it will immediately call your client script but it will also postback (perhaps cancelling your client script).

OnClientClick="javascript:callAjax();return false;"

I'm always forgetting to add that for server-side asp:buttons that only call client script (or ajax from client script).

Also I would move your function callAjax()  Javascript inside of the </form> tag and surround the <script> with a <telerik:RadCodeBlock>  (Actually if you surround it with a telerik:RadCodeBlock tag you could move it back into the <head> section were javascript belongs.

Hope that helps...
0
Suresh
Top achievements
Rank 1
answered on 17 Jul 2008, 11:21 PM
Thanks a lot,

now i can able to do without postback, but still i'm facing one pbm, it's not updating the radgrid/page.

i just used following code in Ajax request event,

TextBox1.Text = "Through Ajax";
BindGrid();

but its not updating textbox value either datagrid. What could be the reason?
 
0
Lyle Groome
Top achievements
Rank 2
answered on 24 Jul 2008, 09:14 PM
The standard way that telerik supports rebinding is to create a NeedDataSource server-side event handler for your Grid. In that event you basically only set a RadGrid1.DataSource = somedatasource.
And anytime in any other event you can just call RadGrid1.Rebind() which looks again at the need datasource and then rebind's the grid.  See Here for simple example.

but..
If you knew all that and your page still isn't working, it could be that your controls aren't also inside either the RadAjaxManager or RadUpdatePanel (whichever you are using). Anything you change in an ajax request must be surrounded by your RadUpdatePanel or have a trigger setup for the target controls in order for you to see any change from the server-side (otherwise you won't actually see your change until after your next postback.)

Hope that helps.
Tags
Ajax
Asked by
Suresh
Top achievements
Rank 1
Answers by
Suresh
Top achievements
Rank 1
Lyle Groome
Top achievements
Rank 2
Share this question
or