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

[Solved] postback on button click on an ajaxified grid

3 Answers 245 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Phani Alla
Top achievements
Rank 1
Phani Alla asked on 30 Jun 2009, 05:09 PM
Hello, I've created a sharepoint web part with rad ajax manager and a grid. the grid has a couple of image buttons which on clicking need to do a full post back (this is to refresh the whole page so that a grid in another webpart gets updated).
RadGrid oGrid = new RadGrid();  
            oGrid.ID = "ProjectGrid";  
            oGrid.Skin = "WebBlue";  
            //oGrid.Width = new Unit(100, UnitType.Percentage);  
            oGrid.AutoGenerateColumns = false;  
            oGrid.AllowPaging = true;  
            oGrid.AllowSorting = true;  
            oGrid.ClientSettings.Resizing.AllowColumnResize = true;  
            oGrid.ClientSettings.AllowColumnsReorder = true;  
            //oGrid.MasterTableView.allow  
           oGrid.NeedDataSource += new GridNeedDataSourceEventHandler(oGrid_NeedDataSource);  
            oGrid.MasterTableView.Columns.Clear();  
            GridButtonColumn Print = new GridButtonColumn();  
            Print.ButtonType = GridButtonColumnType.ImageButton;  
            Print.ImageUrl = @"\_layouts\wpresources\images\print.gif";  
            Print.UniqueName = "Print";  
            Print.CommandName = "Print";  
            Print.ItemStyle.Width = new Unit(10, UnitType.Pixel);  
            oGrid.MasterTableView.Columns.Add(Print);  
oGrid.ItemCommand += new GridCommandEventHandler(oGrid_ItemCommand);  
            oGrid.ItemCreated += new GridItemEventHandler(oGrid_ItemCreated); 

I then used the itemCreatedEvent to call the __dopostback function
void oGrid_ItemCreated(object sender, GridItemEventArgs e)  
        {  
              
            if (e.Item is GridDataItem)  
            {  
                GridDataItem dataItem = e.Item as GridDataItem;  
                ImageButton imgbtn1 = dataItem["Print"].Controls[0] as ImageButton;  
                ImageButton imgbtn2 = dataItem["CreateNew"].Controls[0] as ImageButton;  
                ImageButton imgbtn3 = dataItem["MakeActive"].Controls[0] as ImageButton;  
                ImageButton imgbtn4 = dataItem["CopyToClipboard"].Controls[0] as ImageButton;  
                imgbtn1.OnClientClick = String.Format(@"{0}.__doPostBack(""{1}"",""{2}"");return false;", ((RadAjaxManager)FindControl("RadAjaxManager1")), imgbtn1.UniqueID, imgbtn1.CommandArgument);  
            }  
        }  
 
Im creating the RadAjaxManager1 in CreateChildControls() method and ive added the grid to be ajaxified to the ajaxsettings of the radAjaxManager on OnLoad Event.
I'm getting the following javascript error when trying to click on the print icon.

Error: ctl00_m_g_c8e8aeac_14ee_41bf_ad30_478d4ab3f78b_RadAjaxManager1 is undefined.

Any idea what i'm missing. I would appreciate any help. Thank you.

Phani

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 03 Jul 2009, 11:36 AM
Hello,

Indeed, the best place for creating and adding RadAjaxManager to the page controls collection is the Page_Init method. Otherwise it might not work properly.
Regarding your code for invoking regular postback: I went through it and iIt looks fine to me. However, could you please try modifying it as below and see if it works this way:

imgbtn1.OnClientClick = String.Format(@"$find(""{0}"").__doPostBack(""{1}"",""{2}"");return false;",   
    RadAjaxManager.GetCurrent(Page).ClientID, imgbtn1.UniqueID, imgbtn1.CommandArgument);  

Check it out and let me know how it goes.

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Phani Alla
Top achievements
Rank 1
answered on 06 Jul 2009, 03:47 PM
Hi Lana, Thank you for your reply. I've changed my code to use AjaxManagerProxy, as I have another webpart on the page which uses an ajaxManager. I am adding the AjaxManager to the page onInit of that other webpart. I tried to replace the line of code on the itemCreated event with the line you provided. Now I get an error "null is null or not an object" at the following line
$find("ctl00_m_g_b905aa12_90d8_4ebd_8816_6f9dd7829e46_RadAjaxManager1").__doPostBack( 

I do not see a control with that ID when i do a viewSource. Any idea what I'm missing. Here is how I'm adding the ajax manager to the page in the OnInit Method.
 protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page); 
            if (ajaxManager == null) 
            { 
                ajaxManager = new RadAjaxManager(); 
                ajaxManager.ID = "RadAjaxManager1"
                Controls.Add(ajaxManager); 
                if (!Page.Items.Contains(typeof(RadAjaxManager))) 
                    this.Page.Items.Add(typeof(RadAjaxManager), ajaxManager); 
            } 
            Page.ClientScript.RegisterStartupScript(typeof(Clipboard), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true); 
            if (this.Page.Form != null) 
            { 
                string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"]; 
                if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();") 
                { 
                    this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();"; 
                } 
            } 
 
            System.Web.UI.ScriptManager scriptManager = System.Web.UI.ScriptManager.GetCurrent(Page); 
            if (scriptManager == null) 
            { 
                scriptManager = new ScriptManager(); 
                //scriptManager.EnablePageMethods = true
                this.Controls.Add(scriptManager); 
            } 
            EnsureChildControls(); 
        } 
0
Iana Tsolova
Telerik team
answered on 07 Jul 2009, 03:23 PM
Hi Phani,

Your code looks fine to me. However, you can try adding the ScriptManager and than the RadAjaxManager to the controls collection. You can also check if the error persists when the control with the manager is added before the other web part on the page.
Additionally, please check what RadAjaxManager.GetCurrent(Page) returns in the ItemCreated event.

Let me know how it goes.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
Phani Alla
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Phani Alla
Top achievements
Rank 1
Share this question
or