Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET Modal Pop Up and VB

Posted on 2009-04-02
8
Medium Priority
?
801 Views
Last Modified: 2012-05-06
I am creating an ASP.NET website that has a list of 25 links (linkButton controls).  If someone clicks a link, I want to check to see if their ZipCode is saved in a cookie - if not, I want to pop up a modal popup box that asks for the zipcode.

I have the modal popup box working - I can check to see if a cookie has been set(on the codebehind page) - but i can't do it without post back.  So the page refreshes before showing the modal pop up and it doesn't look quite right.

Does anyone have any ideas how I would go about this?

Thanks for the help!  I'm learning by doing - so I hope this makes sense.

0
Comment
Question by:steverguy
[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
  • 2
8 Comments
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24056305
Try this

'parent page
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="page1.aspx.cs" Inherits="page1" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Parent Webform</title>
<script language="javascript">
function OpenChild()
{
var ParmA = retvalA.value;
var ParmB = retvalB.value;
var ParmC = retvalC.value;
var MyArgs = new Array(ParmA, ParmB, ParmC);
var WinSettings = "center:yes;resizable:no;dialogHeight:300px"
// ALTER BELOW LINE - supply correct URL for Child Form
var MyArgs = window.showModalDialog("page2.aspx", MyArgs, WinSettings);
if (MyArgs == null)
{
window.alert("Nothing returned from child. No changes made to input boxes");
}
else
{
retvalA.value=MyArgs[0].toString();
retvalB.value=MyArgs[1].toString();
retvalC.value=MyArgs[2].toString();
Window.location.reload();
 
}
}
</script>
</HEAD>
<body>
<P><INPUT id="retvalA" type="text" value="AAA"/></P>
<P><INPUT id="retvalB" type="text" value="BBB"/></P>
<P><INPUT id="retvalC" type="text" value="CCC"/></P>
<P><BUTTON onclick="OpenChild()" type="button">Open Child Window</BUTTON></P>
</body>
</HTML>
 
Child Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Child Webform</TITLE>
<script language="javascript">
function Done() {
var ParmA = tbParamA.value;
var ParmB = tbParamB.value;
var ParmC = tbParamC.value;
var MyArgs = new Array(ParmA, ParmB, ParmC);
window.returnValue = MyArgs;
window.close();
}
 
</script>
</HEAD>
<BODY>
<P>Param A:<INPUT id="tbParamA" TYPE="text"/></P>
<P>Param B:<INPUT ID="tbParamB" TYPE="text"/></P>
<P>Param C:<INPUT ID="tbParamC" TYPE="text"/></P>
<BUTTON onclick="Done()" type="button">OK</BUTTON>
</BODY>
</HTML>

Open in new window

0
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24056323
Sorry i didnt read your requirements properly. the above code is for the model popup window

What you can do is store the required info in the session and onclick do a javascript check
Somthing like var MySessionvalue = <% = Session("key") %>;

then see if its empty then pop up the window else do somthing else

Asish
0
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24056339
if you need extra explanation then let me know.
0
Independent Software Vendors: 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!

 
LVL 4

Expert Comment

by:mahadevan_v
ID: 24056858
you can use a simple ajax page to do this .. return the result to the page which is shown in dialog.. it will avoid the post back
0
 
LVL 1

Author Comment

by:steverguy
ID: 24059777
Ok, I feel like I'm getting really close on this (had to go to bed last night  - wasn't seeing straight)

I'm finding all sorts of code that does kind of what I'm looking for - and I can see how both solutions above are leading to the desired results.  But something's missing.

Here's the code I have for the ModalPopUp Box:
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none" Width="233px">
                   <p>Please enter your zip code:<br />
                   <asp:TextBox ID="ZipCode" runat="server"></asp:TextBox>
                   <br />
                      <asp:Button ID="OkButton" runat="server" Text="OK" />
                      <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
                   </p>
                </asp:Panel>
   <br />
   <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
             TargetControlID="lb_Architects"
             PopupControlID="Panel1"
             BackgroundCssClass="modalBackground"
             DropShadow="true"
             OkControlID="OkButton"
             CancelControlID="CancelButton" />

I have 25 links that will be like this one: <asp:LinkButton ID="lb_Furniture" runat="server" CssClass="CatNavMain" OnClientClick="someJsYouWant();">Furniture & Appliances</asp:LinkButton>
(following the example from somehere on the web)

The javascript i have is:
 function someJsYouWant(){  
                alert('HelloSO');
            ;}

Taking AsishRaj's example of using a session variable to set a Javascript variable, I can see how to check the value i need...  But I can't see how to pop up the modal box - if the Session Variable is empty.
If the session variable has a value,  I don't want the modal popup box to show at all.

I was able to accomplish this if I postback - but the refresh doesn't look right.

Thanks for your help!
0
 
LVL 9

Accepted Solution

by:
AsishRaj earned 2000 total points
ID: 24064062
Try this - untested code - out of the head

<script>
function someJsYouWant(){ 
   var test;
   if(test!=null){
      document.write("exists!");
   }else{
       var modal = $find('ModalPopupExtender1'); 
       modal.show();
   }
}
</script> 

Open in new window

0
 
LVL 1

Author Comment

by:steverguy
ID: 24064134
Thanks! That worked great.
0
 
LVL 9

Expert Comment

by:AsishRaj
ID: 24064248
glad it worked for you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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