Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

call javascript from vb.net

Posted on 2011-05-03
25
Medium Priority
?
699 Views
Last Modified: 2012-05-11
I want to call for this javascript below
____________________________________
    function openWin2() {
            var oWnd = radopen("Dialogalternateitem.aspx", "RadWindow3");
        }
______________________________________

Normally, I can open this from a button click even as seen below
_____________________________________________________
vb code
ImageButtonPopup.Attributes.Add("onclick", "openWin(); return false;")

HTML button
<asp:ImageButton ID="ImageButtonPopup" runat="server"
                ImageUrl="~/images/continue.png" Visible="False" />

____________________________________________________
So my thought was to skip button click and just call javascript code by doing this below but its not doing anything.....???
___________________________________________
 Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "openwin2();", True)
0
Comment
Question by:Wigging
  • 11
  • 7
  • 6
  • +1
25 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35516483
Could it be just the capital "W"?

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "openWin2();", True)
0
 

Author Comment

by:Wigging
ID: 35516492
is it case sensitive?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35516496
Yes
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:radcaesar
ID: 35516507
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("Body1");
body.Attributes.Add("onload", "Function1()");
0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700122
The only thing you should do is add onclientclick attribute to the asp:ImageButton
ex::
<asp:ImageButton ID="ImageButtonPopup" runat="server" ImageUrl="~/images/continue.png" Visible="False" onclientclick="openWin2()"  />
0
 

Author Comment

by:Wigging
ID: 35700135
I know but I dont want to open from click button but instead from server side code?  

how would I accomplish this?  
0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700269
Add <script> tags

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script>openWin2();</script>", True);
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700328
"True" means print the script tags to the response.

Why not just do this if you want the new window to open when the parent page loads.

 Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "radopen(""Dialogalternateitem.aspx"", ""RadWindow3"");", True)
0
 

Author Comment

by:Wigging
ID: 35700345
can I add this code below
Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "radopen(""Dialogalternateitem.aspx"", ""RadWindow3"");", True)

anywhere on my server side code and it should open?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700349
Add it the the Page_Load function for that web form.
0
 

Author Comment

by:Wigging
ID: 35700369
ok but I need to only open it if a condition is met? is this possible as well?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700377
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "window.open (""test1.htm"",""mywindow"");", True)
    End Sub

Also, there must be a runat="server" form on the aspx page for it to work.

<body>
<form runat="server" ID="form1"></form>
</body>
0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700384
Just add <script> tags to your code:
For example:

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script> radopen(""Dialogalternateitem.aspx"", ""RadWindow3"");</script>", True)

Or

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script>openWin2();</script>", True)


Or try this

ClientScript.RegisterStartupScript(Me.GetType(), "alert", @"<script>alert('aaaa');</script>", True)

0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700387
Obviously, you would replace my test script with your radopen() function call.
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700398
@Hobbiett,

Script tags will automatically be printed to the response if "True" is the last argument.
0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700434
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700486
@Hobbiet,

Not sure what you are pointing out there. The remarks do not talk about script tags. Anyway, we are using ClientScript, not ClientScriptManager.
0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700553
@tommyBoy you are right, Script tags will automatically be printed to the response if "True" is the last argument.



0
 
LVL 1

Expert Comment

by:Hobbiett
ID: 35700583
@tommyBoy "About Not sure what you are pointing out there. The remarks do not talk about script tags. Anyway, we are using ClientScript, not ClientScriptManager"

Page.ClientScript is a ClientScriptManager instance ;)


public System.Web.UI.ClientScriptManager ClientScript { get; }

0
 

Author Comment

by:Wigging
ID: 35700674
when I use this
Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script>openWin2();</script>", True)


i get syntax error on that line below

<script>openWin2();</script>Sys.Application.initialize();
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700732
Ok, so we will include the extra step.

Dim cs As ClientScriptManager = ClientScript
cs.RegisterStartupScript(Me.GetType(), "alert", "radopen(""Dialogalternateitem.aspx"", ""RadWindow3"");", True)
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 35700773
@wigging,

Use the code shown in my last post
0
 

Author Comment

by:Wigging
ID: 35700859
@tommyboy

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB7.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
Timestamp: Thu, 5 May 2011 18:42:36 UTC


Message: 'undefined' is null or not an object
Line: 6769
Char: 1
Code: 0
URI: http://maple/test35/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=ctl00_RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d3.5.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3a3bbfe379-348b-450d-86a7-bb22e53c1978%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%2c+Version%3d2010.3.1317.35%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3aen-US%3ad7b88a55-4248-43ee-a9ed-d9058fd97467%3a16e4e7cd%3af7645509%3a24ee1bba%3ae330518b%3a1e771326%3ac8618e41%3a874f8ea2%3af46195d3%3a19620875%3a490a9d4e%3abd8f85e4


Message: Object doesn't support this property or method
Line: 503
Char: 1
Code: 0
URI: http://maple/test35/omcart.aspx

0
 

Author Comment

by:Wigging
ID: 35700956
also at @tommyboy i have this window manager below in html pahe.....is this correct?

                                <telerik:RadWindowManager ID="RadWindowManager1"
                                                ShowContentDuringLoad="False"
                                                AutoSize="True"  
                                                VisibleStatusbar="False"
                                                ReloadOnShow="True"  
                                                runat="server"
                                                Opacity="99"  
                                                BehaviorsAutoSize="true"
                                                Skin="Sunset"
                                                EnableShadow="True" >
                                                <Windows>
                                                    <telerik:RadWindow ID="RadWindow2" runat="server" Behaviors="Close" OnClientClose="OnClientClose"
                                                        NavigateUrl="DialogCS2.aspx">
                                                    </telerik:RadWindow>
                                           
                                               
                                           
                                                    <telerik:RadWindow ID="RadWindow6"  NavigateUrl="dialogalternateitem.aspx" runat="server" Behaviors="Close">
                                                   
                                                    </telerik:RadWindow>
                                           
                                               
                                           
                                                </Windows>
                                            </telerik:RadWindowManager>
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 total points
ID: 35701277
1. Is there a form tag on the page with a runat="server" attribute?

2. Verify that the call to radopen() is printing to the page. Look at the view source for the rendered page. Do you see the call to radopen() inside a script block?

3. Where is the actual radopen() script located on the page? Or is it in an external file. The placement of the radopen() function call has to be rendered on the page at a point after the actual function is available to be called. You may have to delay the call until the page is fully loaded.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question