calling javascript from asp.net c# application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Um9iZXJ0IFNtaXRo?=

    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_Ro wUpdating(objec t sender,
    GridViewUpdateE ventArgs e)
    {

    }

    Do you know of any way of kicking off the SetUnSavedChang es 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 SetUnSavedChang es(callBackPane l)
    {
    UnSavedChanges = true;
    }


    function SetSavedChanges (callBackPanel)
    {
    UnSavedChanges = false;

    }


    function AdminTabStripHa ndler(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;
    }
    }


  • Artur Borecki MCP

    #2
    Re: calling javascript from asp.net c# application

    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.R egisterStartupS cript(this, this.GetType(),
    typeof(TYPE_OF_ CONTAINING_PAGE ).FullName, script, true);

    if not

    ClientScriptMan ager.RegisterSt artupScript( ... );

    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" <RobertSmith@di scussions.micro soft.comwrote in message
    news:679D6271-3E87-41E5-8081-50C18F7426B4@mi crosoft.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_Ro wUpdating(objec t sender,
    GridViewUpdateE ventArgs e)
    {
    >
    }
    >
    Do you know of any way of kicking off the SetUnSavedChang es 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 SetUnSavedChang es(callBackPane l)
    {
    UnSavedChanges = true;
    }
    >
    >
    function SetSavedChanges (callBackPanel)
    {
    UnSavedChanges = false;
    >
    }
    >
    >
    function AdminTabStripHa ndler(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;
    }
    }
    >
    >

    Comment

    Working...