Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to call Javascript alertHow to call Javascript alert
Previous
 
Next
New Post
6/16/2010 1:31 PM
 
I would like to pass a string to a java script alert and have it alert the user. So the message could be determined in the codebehind and then passed to the alert function.

I have been foraging the net for some clear examples but have not found any.

Problem's I am having are:
If this code is pasted into my Code behind I get no errors but it doesn't work
Dim cs As ClientScriptManager = Page.ClientScript
Dim cstype As Type = Me.GetType()
cs.RegisterClientScriptBlock(cstype, "Javascript", "<script> Record Added Successfully')</script>")

do I need to put the script into the actual ASPX page for the module or the default.aspx?
<script type="text/javascript">
    function AlertUser(TextString) {
         extString)}
</script>

I really do not know what the basic requirements are.
thanks
 
New Post
6/17/2010 7:41 PM
 
Dan Rowe wrote:
I would like to pass a string to a java script alert and have it alert the user. So the message could be determined in the codebehind and then passed to the alert function.

I have been foraging the net for some clear examples but have not found any.

Problem's I am having are:
If this code is pasted into my Code behind I get no errors but it doesn't work
Dim cs As ClientScriptManager = Page.ClientScript
Dim cstype As Type = Me.GetType()
cs.RegisterClientScriptBlock(cstype, "Javascript", "<script> Record Added Successfully')script>")

do I need to put the script into the actual ASPX page for the module or the default.aspx?
<script type="text/javascript">
    function AlertUser(TextString) {
         extString)}
script>

I really do not know what the basic requirements are.
thanks

 Hey:

Well, you're on the right track, but it's not as convoluted as you're making it.  You need to create a string that contains the javascript (the COMPLETE javascript) and add it to this call:

cs.RegisterClientScriptBlock(cstype, "Javascript", sbmyjavascriptfunction.ToString())

So, below you'd have something (has to be VALID javascript!):

stringbuilder smyjavascriptfunction = new StringBuilder();
sbmyjavascriptfunction.Add( "<
script type='text/javascript'>" + "\r\n");
PUT YOUR JAVASCRIPT FUNCTION HERE.
sbmyjavascriptfunction.Add("</script>" + "\r\n");

Then you need to add Attribute to whatever is clicked on to call this javascript function (ie, add an attribute to a button control that processes this alert).

It's basic ajax...you might want to check out some tutorials on google.  Just go there and type 'asp.net javascript alert tutorial".  That results in a ton of good links explaining this in detail.

 
New Post
6/18/2010 9:53 AM
 
You mention attribute to whatever is clicked, Can I simply call the javascript  function from within my VB code to execute the popup?
in other words the user already clicked something
The code behind is processing routines and determines It needs to alert user with some text so it does.

I would like to create a function that can be called from anywhere in my code that would receive the text to show and then popup the dialog.
Like msgbox in VB
 
New Post
7/2/2010 3:41 PM
 
I use the following Function in my DNN website for Javascript alert.

Code: Public Shared Sub yVal message As String) Dim cleanMessage As String = message.Replace("'", "'") Dim script As String = " " Dim page As Page = TryCast(HttpContext.Current.CurrentHandler, Page) If page IsNot Nothing AndAlso Not page.ClientScript.IsClientScriptBlockRegistered("alert") Then page.ClientScript.RegisterClientScriptBlock(GetType(CustomFunctions), "alert", script) End If End Sub


Then in any module I am working on if I want an alert popup I just do CustomFunctions. Message Goes here") Hope that helps, Chris

Edit: The text editor is getting rid of some of the code. I tried using the "Insert Code Snippet button but it wouldn't work, any ideas how to correctly put code in a message?
 
New Post
8/5/2010 4:30 PM
 
I have tried to recreate your sub routine and the closest I get is this:

Public Shared Sub showpopup(ByVal message As String)
Dim cleanMessage As String = message.Replace("'", "'")
Dim script As String = " "
Dim page As Page = TryCast(HttpContext.Current.CurrentHandler, Page)
If page IsNot Nothing AndAlso Not page.ClientScript.IsClientScriptBlockRegistered("alert") Then
page.ClientScript.RegisterClientScriptBlock(GetType(CustomFunctions), "alert", script)
end if
end sub


Obviously I am missing something vital. Excuse my ignorance (Programming 13 years web Dev only 2-3)
I understand that the client side is running the script and I have code that runs pop up when attached to a button or text box but in this case I just want an alert that say  something and then the user clicks it to make it go away.

So this code is registering my javascript with the client on the fly? and then triggering it?

ANy help would be appreciated
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to call Javascript alertHow to call Javascript alert


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out