calling javascript from asp.net c# application

R

Robert Smith

Hi,
I have a the following javascript code(see below) within my asp.net page,
I would like to be able to set the value of UnSavedChanges within my c#
behind code to indicate that changes have been made but not yet saved.
For Example I have a gridview rowUpdating event as follows

protected void gvwCommodity_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{

}

Do you know of any way of kicking off the SetUnSavedChanges event within
this method or setting the UnSavedChanges variable any other way..

Thanx in advance

Robert



///Javascript code below
/// this code uses essential objects and works on the callback panel
onClientClick
// event

var UnSavedChanges

function SetUnSavedChanges(callBackPanel)
{
UnSavedChanges = true;
}


function SetSavedChanges(callBackPanel)
{
UnSavedChanges = false;

}


function AdminTabStripHandler(e, eventInfo)
{
if (UnSavedChanges == true)
{
var RetVal = confirm("Are you Sure you want to leave this screen
without saving changes");
if (RetVal == true)
{
SetSavedChanges();
}
return RetVal;
}
}
 
A

Artur Borecki MCP

If you are using AJAX.NET you can use something like that:

string script = "alert('Hello')"; // put here any script you want,
e.g. call the function.

ScriptManager.RegisterStartupScript(this, this.GetType(),
typeof(TYPE_OF_CONTAINING_PAGE).FullName, script, true);

if not

ClientScriptManager.RegisterStartupScript( ... );

Anyone of above methods will add supplied script to the page and execute
it. "AJAX.NET way" will do it without page postback.


Artur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top