471,356 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

calling javascript from asp.net c# application

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;
}
}
Jun 27 '08 #1
1 1380
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

"Robert Smith" <Ro*********@discussions.microsoft.comwrote in message
news:67**********************************@microsof t.com...
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;
}
}

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Krishna | last post: by
4 posts views Thread by Martin Feuersteiner | last post: by
4 posts views Thread by muralidhargvn | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.