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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

how to open a new window by using a button and link button


i want to open a new pop up window that have the address bar ,statndar button and menu closed or set to no by clicking a button or a link button without using the NavigateUrl because i have a sub routen that runs before redirecting the page.

have an examply :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

if user.text = "a" then

   response.redirect ("popupwindow.aspx ",'width=400,height=200,toolbar=no,
location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,
resizable=no')

end if

End Sub

thanks....
0
bduhaish
Asked:
bduhaish
  • 9
  • 5
  • 5
1 Solution
 
Ramesh SrinivasTechnical ConsultantCommented:
In your page load event just attach an onclick event to your button along with the javascript function to open a window.

Button1.Attributes.Add("onClick", "javascriptFunctionToOpenWindow")

0
 
bduhaishAuthor Commented:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Button1.Attributes.Add("onClick", "javascriptFunctionToOpenWindow")
    End Sub

-------------------------------
in the head tag

<Script Language="JavaScript">
function go() {
var load = window.open('WebForm3.aspx','','scrollbars=no,
menubar=no,height=600,width=800,resizable=yes,toolbar=no,
location=no,status=no'); }
// -->
</Script>

------------------------------------------
<asp:Buttonid="Button1" runat="server" Text="Button" OnClick="go"></asp:Button></TD>
-----------------------------------------------------------------------

problem understanding the idea in the page load ?
0
 
Ramesh SrinivasTechnical ConsultantCommented:
Keep the script tag as is.

you do not need the OnClick="go" part so remove it, should be just:

<asp:Buttonid="Button1" runat="server" Text="Button" ></asp:Button>

Then in page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Button1.Attributes.Add("onClick", "javascript:return go();")
End Sub

What this does is, it attaches the onClick (javascript) event to your asp.net button.
 
Try as above.
0
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.

 
bduhaishAuthor Commented:
still not working ?
0
 
Ramesh SrinivasTechnical ConsultantCommented:
Use this window opening function in your head tag:

function go() {
var w;
if (w) {
      w.location = 'WebForm3.aspx'
} else {
      w = window.open('WebForm3.aspx','','width='800',height='600'');
      if (window.focus) {w.focus()}
      return false;
}
}
0
 
Ramesh SrinivasTechnical ConsultantCommented:
BTW: You can add the scroll bar and other properties after you know it is working.
0
 
bduhaishAuthor Commented:
sorry for been late, but still not working and is it working with you because I cant get what  is wrong and what about the sub routine after I press the button I don’t see you mentioned any thing about it .
-------------------------------------

0
 
Ramesh SrinivasTechnical ConsultantCommented:
There is no subroutine, the button just calls the javascript function which is attached to its event using the attributes.add method.

0
 
bduhaishAuthor Commented:
First:
what i said previous in my first comment is i have an example witch is a login page and after i specify some couple of lines it will be redirect to another page ,so my question is where should i put this subroutine

Second :
Assuming that we only want to open a new page, but still facing the same problem.











0
 
bduhaishAuthor Commented:
any help please .....
0
 
bduhaishAuthor Commented:
help please .....
0
 
b1xml2Commented:
looking
0
 
b1xml2Commented:
Private Sub Button1_Click(ByVal sender As Object,ByVal e As EventArgs Handles Button1.Click
      If String.Compare(user.text,"a",True) = 0 Then
            Dim builder As New System.Text.StringBuilder(
            builder.AppendFormat("<script language='javascript'>window.open('{0}','{1}','{2}');</script>", _
                  "popupwindow.aspx", _
                  string.Empty, _
                  "width=400,height=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no")
            Page.RegisterStartupScript("popup", builder.ToString())
      End If
End Sub
0
 
bduhaishAuthor Commented:
b1xml2

I’m getting a highlight on    Page.RegisterStartupScript("popup", builder.ToString())

That say’s name builder is not declared and I triad to but them in one line but still getting the error message

Please tray to check them in any application you have because I think my be I have to declare some name spaces or something else.

thanks........
0
 
b1xml2Commented:
Dim builder As New System.Text.StringBuilder()
0
 
bduhaishAuthor Commented:
500% working fine.

Now I’m trying to merge the idea with my login page then I’ll tell what happened

pending
.
.
.
.
.
0
 
b1xml2Commented:
kewl =)
0
 
bduhaishAuthor Commented:
it's working thanks.........

Now there is a new idea has been fire out about if i want the page to be open in the same window or page after I click the button, it's depend on you whether you want me to post it in the same session or close this session and open a new one.
0
 
b1xml2Commented:
new session for everyone to be able to share with u as well pls.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 9
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now