C# ASP.net - Java script

How to write this using C# ASP.net page load event
var script = @"<script type="text/javascript">
    //<![CDATA[
    var GlvDelayedNextPageNo;

    function WebForm_CallbackComplete_SyncFixed() {
        // the var statement ensure the variable is not global
        for (var i = 0; i < __pendingCallbacks.length; i++) {
            callbackObject = __pendingCallbacks[i];
            if (callbackObject && callbackObject.xmlRequest &&
                (callbackObject.xmlRequest.readyState == 4)) {
                // SyncFixed: line move below // WebForm_ExecuteCallback(callbackObject);
                if (!__pendingCallbacks[i].async) {
                    __synchronousCallBackIndex = -1;
                }
                __pendingCallbacks[i] = null;
                var callbackFrameID = "__CALLBACKFRAME" + i;
                var xmlRequestFrame = document.getElementById(callbackFrameID);
                if (xmlRequestFrame) {
                    xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
                }
                // SyncFixed: the following statement has been moved down from above;
                WebForm_ExecuteCallback(callbackObject);
            }
        }
    }

    var OnloadWithoutSyncFixed = window.onload;

    window.onload = function Onload() {
        if (typeof (WebForm_CallbackComplete) == "function") {
            // Set the fixed version
            WebForm_CallbackComplete = WebForm_CallbackComplete_SyncFixed;
            // CallTheOriginal OnLoad
            if (OnloadWithoutSyncFixed != null) OnloadWithoutSyncFixed();
        }
    }
    //]]>
";

Open in new window

LVL 10
ukerandiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
If you just mean "how do I flush some javascript to the browser", then you would use something like:
string script = "<script language=\"javascript\">alert('hello world');</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", script, false);

Open in new window

0
Rajar AhmedConsultantCommented:
Just a minor update from Carl Tawn comment  in order to support multiline coding :
https://msdn.microsoft.com/en-us/library/aa479011.aspx
Page.RegisterClientScriptBlock("MyScript",
           "<script language=javascript>" +
           "if (document.images) {" +
           "MyButton = new Image;" +
           "MyButtonShaded = new Image;" +
           "MyButton.src = 'button1.jpg';" +
           "MyButtonShaded.src = 'button2.jpg';" +
           "}" +
           "else {" +
           "MyButton = '';" +
           "MyButtonShaded = '';" +
           "}" +
           "</script>");

Open in new window


IMO, it would be better if you code this in a sperate script(.js) file instead of embedding in  C#.net coding.

Regards
Rajar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.