2

I love how in ASP.NET the ScriptManager has a composite section which allows one to specify multiple javascript files and it does the legwork of merging them all into one file at runtime.

I.E.

//input scriptB.js, scriptB.js
ScriptManager.CompositeScript.Scripts.Add("~/scriptA.js")//psuedo code
ScriptManager.CompositeScript.Scripts.Add("~/scriptB.js")//psuedo code
//output
scriptC.js

Is it possible to add javascript source directly to the scriptmanager, E.G.:

ScriptManager.CompositeScript.Scripts.Add("alert('hello');")//psuedo code

2 Answers 2

2

You could add script through ScriptManager like this:

ScriptManager.RegisterStartupScript(this, GetType(), ClientID,"alert('hello');", true);

This script will be added directly to page.

Sign up to request clarification or add additional context in comments.

2 Comments

It doesnt merge it with the ScriptManager's almagamated js, so not quite the solution.
Yes it gonna marge script, if you add script whith same key, ClientID in my exapmle
-1

It works for me when I do it like this

Private Sub test()
        ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "k1", "alert('hello')", True)
    End Sub

but when I add SweerAlert to it it wont work

Private Sub test()
            ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "k1", "swal('Please Provide All Valid Message Information!')", True)
        End Sub

do you have any idea why it dont works.

1 Comment

This is not an answer. it's another question. Please post it as a new question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.