difference between Attributes.Add() and Response.write to execute " Javascript"

I am having following problem:

Response.Write("<script>" + "window.location.href=window.showModalDialog('/popopOffer.aspx');" + "</script>");
when I use this code on the button1_Click() event it displays the popop and when I close the popop it doesn't redirect to the required page - goes to the parent page.

 btnCheckout.Attributes.Add("OnClick", "window.location.href=window.showModalDialog('/popopOffer.aspx');");  
             
When I use this code the button1_Click() event it displays the popop but keeps the background blank(can't see the content of the parent page) but redirects to the required page.

the code on the popup page as follows:
______________________
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
// <!CDATA[
function button1_onclick()
 {
//
window.returnValue = "http://CheckoutPage.aspx";
self.close();    
}



// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center><asp:Image ID="Image2" runat="server" /></center><br /><br />
          <div><asp:Localize ID="Offer" runat="server" meta:resourcekey="Offer" /></div><br /><br />
        <center><asp:Image ID="Image1" runat="server" /></center><br /><br />
           <div><asp:Localize ID="OfferDescription" runat="server" meta:resourcekey="OfferDescription" /></div><br />
          <center><input id="button1" type="button" value="Yes,Tell me more"  onclick="button1_onclick()"/>
        </center>
    </div>
    </form>
</body>
</html>

______________________

Any help will be appreciated.
excngexpdpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jinn_hnnlCommented:
The different is:

when you use response.write this piece of code will be added after the page is render,
So when you finished compiling on the server side (the response.write code is executed), after rendered, this script:
<script>" + "window.location.href=window.showModalDialog('/popopOffer.aspx');" + "</script> will be executed.

when you add attribute to the button server btnCheckOut
btnCheckout.Attributes.Add("OnClick", "window.location.href=window.showModalDialog('/popopOffer.aspx');");  

This will add the CLIENT CLICK for this button (same as you do OnClientClick), and this mean, this javascript will be executed when btnCheckOut is clicked. ALL HAPPEN in Client side. (so the page doesn't postback execute the javascript first)

Notice that this is different behaviour from normal server button click (it posted back to server, server run Inint, Page_Load, then btnCheckOut_Click(object sender...)

Hope this helps

JINN

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.