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
Solved

New Window from ASP.net button

Posted on 2007-11-16
13
1,300 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert datetime to time string 10 28
C# LINQ ForEach() question 6 48
jquery tab header text 1 22
Where is this file? 3 25
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 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