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

[Solved] Problem Script registering and RadGrid edit mode

5 Answers 269 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jose
Top achievements
Rank 1
Jose asked on 21 Oct 2008, 02:05 PM
Hi...

I'm trying to dynamically register some client script in a user control Page_Load method... This user control is triggered by a RadGrid through the EditMode...

AJAX SETTINGS :

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
      <AjaxSettings > 
          <telerik:AjaxSetting AjaxControlID="RadGrid1" > 
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"/>  
               </UpdatedControls> 
              </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

GRID :

 <telerik:RadGrid ID="RadGrid1" runat="server">  
        <MasterTableView Name="masterView" GridLines="None" EditMode="PopUp" CommandItemDisplay="Top">  
            <CommandItemSettings AddNewRecordText="Add new entry" RefreshText="Refresh" /> 
            <EditFormSettings UserControlName="Control1.ascx" EditFormType="WebUserControl">  
            </EditFormSettings> 
        </MasterTableView> 
    </telerik:RadGrid> 

USER CONTROL UI
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Control1.ascx.vb" Inherits="TestClientScriptRegister.Control1" %> 
<asp:Button ID="Button1" runat="server" Text="Button" /> 

USER CONTROL SERVER SIDE CODE
 Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
    Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "Test"Me.GetScript(), True)  
    Me.Button1.Attributes("OnClick") = "Test()" 
  End Sub 
 
  Private Function GetScript() As String 
    Dim sb As New System.Text.StringBuilder()  
 
    sb.Append("function Test() {")  
    sb.Append("alert('what?');")  
    sb.Append("}")  
 
    Return sb.ToString()  
  End Function 

Quite basic stuff...  I know that there's some ways to achieve this without any dynamic script registering but for some reasons, I need to do it that way... 
I tried a bunch of stuff without any success...
 - EnablePageHeadUpdate = "true" in the AjaxManager
 - RadScriptManager.RegisterClientScriptBlock
 - Page.ClientScript.RegisterClientScriptBlock
 - RadAjaxManager.GetCurrent(Page).ResponseScripts

Some remarks...
 - Works well when using a radwindow that calls a page containing the user control.
 - Works well when I remove the ajaxsettings that update the RadGrid in the RadAjaxManager.

Am I missing something?  Maybe I'm not using the grid edit mode the right way...  Is there a way to achieve this?

Thanks for your help : )

Jose

5 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 22 Oct 2008, 12:22 PM
Hello Jose,

Please refer to the following help topic which elaborates on this matter. Review the provided approach and let us know if this helps.

Best wishes,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jose
Top achievements
Rank 1
answered on 22 Oct 2008, 01:31 PM
Still not working...

ResponseScripts works fine to register scripts that occurs right away. I need to register a javascript function that will get called later...

I tried with the panel and the place holder...still, no luck...I guess I'm missing something...

Let me explain why I need to dynamically register a client function.  I have a user control that contains a bunch of asp:control within it.  I need to have a client event raised when I click on a button that will disable some other controls.  Now this user control is used multiple times within a single page (or within a user control that gets called by the grid edit form).  This leads us to the main problem : My javascript function appears x times (x = number of instance of my user control) within the page.  The only way I found to fix this is to dynamically register my javascript function in the server OnLoad event, to give it a unique name.
sb.Append("<script type='text/javascript'>")  
sb.Append("function MyFunction" + Me.UniqueID + "() {"

Then assign OnClick attribute of my button

Me.myButton.Attributes.Add("OnClick""MyFunction" + Me.UniqueID + "()"

I know it's asp.net stuff here more than telerik stuff, but I felt like I needed to explain exactly why I'm facing this issue.

Thanks for your support...
0
Jose
Top achievements
Rank 1
answered on 22 Oct 2008, 02:35 PM
Ok, I've found a way to bypass this situation....

All I need is to have my javascript functions directly in the page and those functions would receive the ctrlId in parameters...

function DisableForSelection(ctrl1, ctrl2) {  
 var radctrl= $find(ctrl1);  
 radctrl.disable();  

Still I think this is a workaround, and I do believe that we should be able to register some javascript function dynamically from the load of a user control that gets called by the edit form of a radgrid...

Thanks
0
Maria Ilieva
Telerik team
answered on 23 Oct 2008, 12:22 PM
Hello Jose,

I'm glad that you have managed to fix the issue for now.
Actually all the methods you previously mentioned should work for your scenario. If it is ok for you please open a regular support ticket and send us a sample runnable project which represents the problem with those methods. We will test this locally and advise you further.

Best wishes,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul Mc
Top achievements
Rank 1
answered on 16 Sep 2009, 03:27 PM
Jose

I know this thread has gone cold, but I was wondering if you got a solution to your problem as we're having exactly the same issue here with a popup user control on a radGrid.

Kind regards

Paul



Tags
Grid
Asked by
Jose
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Jose
Top achievements
Rank 1
Paul Mc
Top achievements
Rank 1
Share this question
or