call javascript from vb.net

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)
WiggingAsked:
Who is Participating?
 
Tom BeckCommented:
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
 
Tom BeckCommented:
Could it be just the capital "W"?

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "openWin2();", True)
0
 
WiggingAuthor Commented:
is it case sensitive?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Tom BeckCommented:
Yes
0
 
radcaesarCommented:
HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("Body1");
body.Attributes.Add("onload", "Function1()");
0
 
HobbiettCommented:
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
 
WiggingAuthor Commented:
I know but I dont want to open from click button but instead from server side code?  

how would I accomplish this?  
0
 
HobbiettCommented:
Add <script> tags

Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script>openWin2();</script>", True);
0
 
Tom BeckCommented:
"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
 
WiggingAuthor Commented:
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
 
Tom BeckCommented:
Add it the the Page_Load function for that web form.
0
 
WiggingAuthor Commented:
ok but I need to only open it if a condition is met? is this possible as well?
0
 
Tom BeckCommented:
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
 
HobbiettCommented:
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
 
Tom BeckCommented:
Obviously, you would replace my test script with your radopen() function call.
0
 
Tom BeckCommented:
@Hobbiett,

Script tags will automatically be printed to the response if "True" is the last argument.
0
 
HobbiettCommented:
0
 
Tom BeckCommented:
@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
 
HobbiettCommented:
@tommyBoy you are right, Script tags will automatically be printed to the response if "True" is the last argument.



0
 
HobbiettCommented:
@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
 
WiggingAuthor Commented:
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
 
Tom BeckCommented:
Ok, so we will include the extra step.

Dim cs As ClientScriptManager = ClientScript
cs.RegisterStartupScript(Me.GetType(), "alert", "radopen(""Dialogalternateitem.aspx"", ""RadWindow3"");", True)
0
 
Tom BeckCommented:
@wigging,

Use the code shown in my last post
0
 
WiggingAuthor Commented:
@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
 
WiggingAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.