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

[Solved] Javascript in Telerik controls

2 Answers 237 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 30 Jun 2009, 07:05 PM
Hi All,

When the RAdToolBar Button is clicked , i need to invoke the javascript function. I tried to do in the below method but javascript function is not getting called!! pls help
this is ascx(since I'm using an user ctrl)

<

 

script type="text/javascript">

 

 

function DateValid()

 

{

alert(

"End Date cannot be lesser than the Start Date");

 

}

and in ascx.cs, I have the below lines to call the js function.

 

 

if (obDoSchedule.DtStartDate >= obDoSchedule.DtEndDate)

 

{

ctlButtonBar.Attributes.Add(

"onClick", "return DateValid();");

 

}

Is this correct? I'm not getting the javascript alert msg even if DtStartDate >=DtEndDate.Pls help!!

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Jul 2009, 10:16 AM
Hi Zaheka,

I tried your code and it is working fine in my end. I am getting the alert when clicking the ToolBarButton after adding the OnClick attribute to RadToolBar. If you want to show alert right from server code instead of adding onclick Attribute from server, then you can try the following code.

C#:
 
ScriptManager.RegisterStartupScript(thisthis.GetType(), "MyScript""DateValid();"true); // shows alert

Another option is attaching OnClientButtonClicked event for RadToolBar and check for condition (if possible) in client side to show alert.

Thanks,
Princy.
0
Sameh
Top achievements
Rank 1
answered on 08 Sep 2009, 07:25 AM

Hello Princy,

 

I have a similar problem to Zeheka's but on the ItemCommand event.

I've tried 

 

Response.Write(

"<script ... >alert('something')</script>"),

 

ScriptManager

 

.RegisterStartupScript(page, page.GetType(), "myKey""<script ... >alert('something')</script>", false),
page.RegisterStartupScript(
"myKey", jScript),
and

 

page.ClientScript.RegisterStartupScript(page.GetType(),

"myKey", "<script ... >alert('something')</script>").

but all didn't work!, so could you please tell me how to solve this issue ?

my original code:

 

public static void alert(System.Web.UI.Page page, string msg)

 

{

 

    string jScript= "<script>alert ('something')</script>";

 

 

    ScriptManager.RegisterStartupScript(page, page.GetType(), "keyClientBlock", jScript, false);

 

    //page.ClientScript.RegisterStartupScript(page.GetType(),

"myKey", jScript);

 

    //page.RegisterStartupScript(

"keyClientBlock", jScript);

 

}

 

 

and note that the page is a content aspx page

Regards.

Tags
Grid
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sameh
Top achievements
Rank 1
Share this question
or