hi,
how can i register a script on asyncPostBack and can check in the next asynPostback if the script is on side ?
i use ajax with scriptmanager and updatepanel on my website.
sometimes i will give the user (after a asyncPostBack) a alert-message about javascript...
i have tryed following:
PrivateSub RegisterMsg(ByVal strMessageAsString,ByVal strScriptTagAsString)Dim strScriptAsString ="alert(""" & strMessage &""");"
If (Not Page.ClientScript.IsClientScriptBlockRegistered("key"))Then
ScriptManager.RegisterClientScriptBlock(Me,Me.GetType(),"key", strScript,True)EndIf
EndSub
the IsClientScriptBlockRegistered-methode every time gives false back...thx
Use ScriptManager.RegisterStartupScript() and drop the IsBlockRegistered check.
now i have:
Private Sub RegisterMsg(ByVal strMessage As String, ByVal strScriptTag As String)
Dim strScript As String = "alert(""" & strMessage & """);"
If (Not Page.ClientScript.IsClientScriptBlockRegistered("key")) Then
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "key", strScript, True)
End If
End Sub
and it is the same...it did not work correct, the IsClientScriptBlockRegistered-Method returns every time false and because of this the script will be written a second one, and third one and so on...
Hi,
Since the script is created dynamically, it won't be persisted between different requests.
So, before the method is called on the second request, this script block does not exist.
And my suggestion is you don't have to call this multiple times, just call it on initial request and it'll always stay on the page since the page isn't fully refreshed.
the problem is that the appl. dont makes really postbacks during running, only partial postbacks...
and my wish is that i will register and unregister scripts during partial postbacks...how can i do it ?
For partial postback, you can register new scripts.
But you can't unregister existed scripts on server side.
Has there been any progress made on this issue? I am just experiencing this now.
I've overriden OnInit with the following (similar) code:
if (!Page.ClientScript.IsClientScriptBlockRegistered(typeof(Page),"MyScript")
{
// use StringBuilder/StringWriter to build script
ScriptManager.RegisterClientScriptBlock(this,typeof(Page),"MyScript",sb.ToString(),true);
}
But the conditional is always true so the script gets recreated every time there is an asyncPostback.
One thing I noticed (using Firebug in Firefox) is on the initial load of the page the script is created
within the form and then on each successive asyncPostback a new script is created in the <head>.
Why is there no IsClientScriptBlockRegistered function in the ScriptManager class? Is that the problem?
That the Page.ClientScript and ScriptManager are looking at two different collections of scripts?
No comments:
Post a Comment