Showing posts with label dear. Show all posts
Showing posts with label dear. Show all posts

Wednesday, March 28, 2012

Calling JavaScript Function From C#

Dear Team

i am using VS2005 ASP.NET 2.0 C# JavaScript AJAX
i want on timer tick in side uodate panel to call javascript Function()
so how can i do that.

thank you

I would very much like to know how to do that too.

I have a ModalPopup containing SimpleViewer, and I need to set the path to an xml file when the user clicks an imagebutton, but as there is no postback going on I can't add that path or whatever it might be to the JavaScript block.

So I relaly need for the JavaScript block to be "loaded" and executed when the user clicks one of many buttons and then load the javascript based on that.


This is a great resource on using a TimerControl with an UpdatePanel:

http://ajax.asp.net/docs/tutorials/IntroToTimerControl.aspx

However if you want to execute a JavaScript function before/during/after an UpdatePanel is refreshed you will need to explore the PageRequestManagerClass:

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

You can add the following Javascript to a page:

<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
function pageLoaded(sender, args) {
if (args.get_panelsUpdated().length > 0){
alert('a panel was just updated!');
// doSomeFunction();
}
}
</script>

Cheers,
Al

Monday, March 26, 2012

Call RegisterStartupScript problem

Dear friends,

I'm having problems to execute a RegisterStartupScript when I click on a button.
For example:

protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "<script language='javascript'>alert('OK');</script>" );
}

If I disable the Atlas tags, the RegisterStartupScript works OK, but if I enable the Atlas tags, It doens't work.

How I correct this?

Try setting addScript Tags = True instead

Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('OK');", True);

RG


I put the True in the last parameter but not works.
Remember thar I'm using Atlas ok.

Do you havy any other sugestion?


just putting the following line in a button even which is inside the update panel works fine for me

Page.ClientScript.RegisterStartupScript(typeof(Page),"OnLoad","alert('OK');",true);

there must be some other issues in the page, you have to show the code.

Thanx


Not work again.

All my controls are inside the same updatepanel, for example:
...
<body>
<form .....>
<atlas:updatepanel .....>
//Here all tags and all controls
</atlas>
</form>
</body>

Is It a problem?


well you have to paste the whole non working code, without the code its hard to tell...


use following code

protected void btnSave_Click(object sender, ImageClickEventArgs e)
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "OnLoad", "alert('OK');",true );
}

I think u'r code remain having "<script language='javascript'>alert('OK');</script>" . This is the problem. U shouldn't use "<script" tag if last parametere is 'true'


I have found that I must have the semi-colon after the script. EG:


page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ShowMsg", "alert('hi')", true);


doesn't work BUT


page.ClientScript.RegisterClientScriptBlock(typeof(Page), "ShowMsg", "alert('hi');", true);

does!


is there a solution? I have the same porblem like rasl


http://ajax.asp.net/docs/mref/T_System_Web_UI_ScriptManager.aspx

You can use the scriptmanager.

Dim msgAsString ="Group '" & u.GroupCode &"' has been deleted."
ScriptManager.RegisterStartupScript(Me.Page,GetType(String),"alertdelete","reportMessage('" & Utils.ForJavascript(msg) &"');",True)