Solved

New Window from ASP.net button

Posted on 2007-11-16
13
1,307 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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