Solved

New Window from ASP.net button

Posted on 2007-11-16
13
1,294 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now