Hello all,
I have a piece of Javascript code that I need to execute after Page_Load according to a certain condition.
Now this Page_Load event is being fired using the Microsoft's AJAX Timer every 10 seconds. In the Page_Load I'm setting a value to a hidden field, so Javascript can check if to execute or not... (did I explained myself correctly?, I'm not quite good at it and at English).
How can I do this? If it can be done?
Thanks!!
I think u are on the right path. Just check the condition of the hidden field with the value u want it to have and if it satisfies execute the java script code by registering the script code.
so you mean I write the Javascript on that Page_Load by means of StringBuilder and then register it? Will it execute?
yes i mean that?you?create?a?script?block?through?a?string?builder?and?then?register?it?through?a?RegisterClientScript?Block.
I think if you paste your current code here may be i can help you much better way.
Here's how i do it;
Protected sub Page_Load(sender as object, e as eventargs) me.handles.load
JavaScript_Functions()
end sub
Private Sub JavaScript_Functions()
dim strScript as string = ""
strScript += "function dosomthing()"
strScript += "{"
strScript += " alert('hello world');"
strScript += " return false;"
strScript += "}"
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "JavaScript_Functions", strScript, true)
end sub
HTML
<asp:Button ID="btnTest" Text="Click Me" OnClientClick="return dosomthing();" runat="server" />
No comments:
Post a Comment