Solved

New Window from ASP.net button

Posted on 2007-11-16
13
1,305 Views
Last Modified: 2013-11-26
I have a validate button, I want it to check the fields on the form and then open a new window with the list of errors.  The button.attributes.add("onclick".......) does not work, because that runs before the validate code has a chance to run, so the second window is blank.  Just wondering how to call the second window (kind of like a popup), after the validate code has ran.
0
Comment
Question by:sborchers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 20300484
There is a cool solution here

http://www.codeproject.com/aspnet/asppopup.asp
http://www.eeeksoft.net/files/popuptest/Default.aspx

This is a popup user control which is pretty cool

Satheesh
0
 
LVL 35

Expert Comment

by:YZlat
ID: 20300706
use javcascript window.open
0
 

Author Comment

by:sborchers
ID: 20300773
Can you give me an example of javascript inside the click event of a button.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 5

Expert Comment

by:ICINTRACOM
ID: 20300881
It would look like this -

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm ( 'Confirm Delete!' )" Text="Delete"></asp:LinkButton>
0
 

Author Comment

by:sborchers
ID: 20301033
The button i'm using is not a link button, just a regular asp:button.  Once the button is click, it needs to run the validate code before opening up the 'popup' window.  I'm looking for validation first, then if needed open a popup window.
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20301115
You can do like this
if (sent == true)
      {
      Page.RegisterClientScriptBlock("Myscript", "<script language='javascript'>alert('Email has been sent to ESL');</script>");

instead of alert you can have your window.open method.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 20301124
button1.Attributes.Add("onclick", "javascript:window.open('your window address'); return false;");
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20301196
Guys,
his point is that he has to execute a server side validation and based on that he has to show the errors in a different window.When you add attributes the client script will execute before the page ia post back.
So basically he has to first do the server validate and then call the javascript to open a separate window to show the error message. In my previous post,I am sending an email with smtp class and then showing a javascript alert.So your Page.RegisterClientScriptBlock will be the next statment after the server code.
HTH
0
 

Author Comment

by:sborchers
ID: 20301231
Thanks spprivate.  Here is code.

    Protected Sub butLabNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butLabNext.Click
        Call ValidateRequest()
         more code.......
    End Sub

    Public Sub ValidateRequest()
        blnValid = True
        strErrors = ""
        If Trim(txtLabTestCode.Text) = "" Then
            'Missing Test
            blnvalid = False
            strLabErrors = "No Test was entered."
       end if
'Here is where i want to call another window.
    End Sub


thanks for the help!
0
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
ID: 20302143
In the place you want to call the javascrpt put something like

if (blnvalid == false)
      {
      Page.RegisterClientScriptBlock("Myscript", "<script language='javascript'>window.open(http://site/errorpage.aspx?errormessage=strlaberrors',size of window);</script>");

Please check the javascript syntax and quotes.
HTH
0
 

Author Comment

by:sborchers
ID: 20314866
That code does work to open up a new on a postback.  If i'm using AJAX and the updatepanel, which is triggered by AsyncPostBackTrigger (button click), the call is not made.  I'm assuming since the entire page isn't getting refreshed that is why the call is not occuring.  Is there away to call that page, from an AsyncPostBackTrigger event?
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20320941
Sorry,
I havent tried that in Ajax yet.So I dont have an idea
0
 

Author Closing Comment

by:sborchers
ID: 31409618
I didn't specify I was using AJAX controls, so the answer you gave worked fine.  It just doesn't work with AJAX.  Thanks for the help.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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