Showing posts with label modal. Show all posts
Showing posts with label modal. Show all posts

Wednesday, March 28, 2012

How do I show postback search results on a Modal Popup?

My goal is to show the serach results in a grid view on a model popup after the user enters the search criteria on a page and presses the search button. The OnClick event handler needs to collect the search criteria, get the dataset after querying the database and bind the data to the gridview before displaying the modal popup.

My problem is that the search button's id can't be assigned to the TargetControlID of the ModalPopupProperties as it will not let the OnClick event be fired and process the postback.

Please suggest the solution/workaround.

Thanks much

Display the ModalPopup via script instead?

David,

Do you have an example or a sample of the script that I can take a look at?

The other option would be to dynamically create the popup, after I process my search funcationility. But the question is, how do I invoke the display of the popup after associating the TargetID of the search button to the dynamically created ModelPopup?

Thanks for looking into it.

Vijay


I believe the following post outlines how to display the ModalPopup with script:http://forums.asp.net/thread/1280980.aspx

How do I send email using ajax modal popup extender

I have a panel that sends an email message. I wish to use an ajax modal popup extender to display this panel when a user clicks a "Contact Us" link button. I get an error message when I try to run the application. My code follows.Thank you for any suggestions.

<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID ="ContactUsLinkButton"
PopupControlID ="EmailPopupPanel"
OkControlID="OKButton"
CancelControlID="CancelButton"
DropShadow="true"
BackgroundCssClass ="modalBackground" />
<asp:LinkButton ID="ContactUsLinkButton" runat="server">Contact Us</asp:LinkButton>


<div >
<asp:Panel ID="EmailPopupPanel" runat="server" CssClass ="popupEmail" Width="325px" Style="display: none" >
<asp:Label ID="TitleLabel" runat="server" BackColor="#FFFFC0"
Font-Bold="True" Font-Size="Medium" ForeColor="SteelBlue" Text="Contact D`Stroke Tennis"
Width="300px"></asp:Label>
<br />
<asp:Label ID="InfoLabel" runat="server" Font-Bold="True" Font-Size="Medium" ForeColor="Red"></asp:Label>
<br />
<br />
<asp:Button ID="OKButton" runat="server" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"
Text="OK" Visible="False" /><br />
<span style="color: #990000"><strong><asp:Label ID="FromLabel" runat="server" Text="From:"></asp:Label></strong> </span>
<asp:TextBox ID="FromTextBox" runat="server" Width="250px" ForeColor="DarkRed"></asp:TextBox>
<br />
<br />
<asp:Label ID="ToLabel" runat="server" Text="To: admin@dotnet.itags.org.dstroketennis.com" Width="300px" BackColor="#FFFFC0" Font-Bold="True" ForeColor="DarkRed"></asp:Label>
<br />
<br />
<span style="color: #990000"><strong><asp:Label ID="SubjectLabel" runat="server"
Text="Subject:"></asp:Label></strong></span>
<asp:TextBox ID="SubjectTextBox" runat="server" Width="240px"></asp:TextBox><br />
<br />
<span style="color: #990000"><strong>
<asp:Label ID="MessageLabel" runat="server"
Text="Message:"></asp:Label></strong></span><br />
<asp:TextBox ID="MessageTextBox" runat="server" Height="150px" TextMode="MultiLine"
Width="300px" ForeColor="DarkRed"></asp:TextBox><br />
<asp:Button ID="SendEmailButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="DarkRed" Text="Send Email" Width="173px" />
<br />
<asp:Button ID="CancelButton" runat="server" BackColor="#FFFFC0" BorderColor="DarkRed"
BorderStyle="Solid" Font-Bold="True" ForeColor="SteelBlue" Text="Cancel Email" Width="173px" /></asp:Panel>
</div>
</form>
</body>

Tags:ajax, ie 7, Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null. Parameter name: element

When do you get the Sys.ArgumentNullException error? Also, try getting rid of the Style="display: none" on the Panel...

-Damien


I get the error when the page loads.


I Got rid of the Style "display : none" and I get the same error on page load.


See if this related post helps:http://forums.asp.net/p/1107533/1700376.aspx

-Damien


I also ran across this:http://www.spthorn.com/blog.php?post=28&PHPSESSID=c42ace58bb0f0d24ab3d9d2eef948c4a

-Damien


Thanks Damien. The asp buttons weren't plugged into anything I am guessing. My new challenge with this now is to have the email send, and display a message that the send was a success before leaving modal state.

At least this one issue is handled.

Saturday, March 24, 2012

How do execute a server-side click event for a ModalPopupExtender?

I have created a modal popup to show up during page load. It is my logon dialog box. Anyways, I have set the OkControl property to my logon button to execute some codes through the ModalPopupExtender control staticly and dynamically through Page_Load but both didn't work..

What is my problem?

Thanks!

Ok, I follow the flow from this person website.http://blogs.vertigosoftware.com/alanl/archive/2006/07/25/Creating_a_Confirmation_Using_the_ModalPopup_Extender.aspx It works with a button.

I want to use the SHOW event when the page load but it doesn't work. It seem like it is not rendering the javascript or couldn't find it.

What is my problem?


Hi,

Have you tried this link?

http://blogs.msdn.com/phaniraj/archive/2007/02/20/show-and-hide-modalpopupextender-from-javascript.aspx

How come the toolkit is only available as server controls?

Am I missing something or is this by design? It would be really nice to programmaticly instantiate/dispose etc.. for creating a modal dialog and the other useful behaviors in the toolkit. Just for a laugh, I decided to copy over the JS files for the dropdown menu and got it working (minus some strange errors where dispose() is being called on undefined objects) but it was rather a cumbersome process having to include all the JS files and dependencies. Anyone else doing this sort of thing? Any chance there is a version of the toolkit that is not server control based?

function createDropDownMenu() { var panel = document.createElement("div"); panel.className ="ContextMenuPanel"; panel.style.display ="none"; panel.style.width ="100px"; panel.style.height ="100px"; panel.style.visibility ="hidden"; var target = $get('placeholderDiv').appendChild(panel); var dd_menu =new AjaxControlToolkit.DropDownBehavior($get('TextLabel')); dd_menu.set_dropDownControl(panel); dd_menu.set_dropDownControlID(TextLabel); dd_menu.set_dropArrowImageUrl("images/drop-arrow.gif"); dd_menu.initialize(); dd_menu.show(); }
anyone?

This has been requested, but it's a bit of work to create a process that will extract all the files and put them in the right dependency order, etc. It's something I'd like to do, but isn't super high-priority.

The trick to do this is as follows:

1) Get the scripts loaded by instantiating an extender and pointing it at a dummy control.

<asp:Label ID="dummy" style="display:none;"/>

<ajaxToolkit:SomeExtender TargetControlID="dummy"/>

2) Instantiate the behavior using the $create() helper, notnew

var behavior = $create(AjaxControlToolkit.SomeBehaior, {prop:value,prop2:value2}, null, null, $get('someElement'));


Excellent. This works great. Thanks for the tip!

I guess the ordering in which the scripts load has something to do with it. I modified my code to use your method and it runs cleanly now with no errors.


Good - yeah if you're okay with that little hand wave, then you don't have to worry about that stuff...

How can the ModalPopup become draggable?

Okay, so following the normal functionality of a modal popup in all desktop apps, the modal popup should be able to be dragged. Is this possible? If so, does that already exist as a property? Or would it need to be added?

For example, say you are on a page with lots of data and you want to add a new data element. So you hit the "Add data" button which neatly shows the modal popup. Uh oh, I forgot what I was going to name it .. and if I could just move this window for a second to see what the last name was .. ugh, looks like I need to close this window to find out.

Obviously, if I needed (or whether the team needed) to add this kind of functionaltiy, then I'd need a draghandle ..

We don't currently support this but it's a good feature request. I've logged it as work item 518. Thanks!

You can also try doing this yourself. I haven't tried this but generally:

1) In ModalPopupExtender add a RequiredScript attribute for typeof(DragPanelExtender)

2) In ModalPopupBehavior, instantiate a Sys.UI.LayoutBehavior and attach it to the control referenced by "PopupControlID"


I think this library is able to get the drag and drop going for the ModalPopup as I have used with similar ModalPopups (not ajax). It does pictures, Divs and other HTML objects.

http://www.walterzorn.com/dragdrop/dragdrop_e.htm

Regards


Sorry .. it was really more of a feature request than anything else. :)

David understood me ..

Anyways, I tried your suggestion last night David.

< .. in ModalPopupBehavior.js ..>this.initialize() = function() { ... "existing init code" ... if (true) { _dragBehavior = new Sys.UI.LayoutBehavior(); _dragControl = $object(_PopupControlID); if (!_dragControl) { _dragControl = new Sys.UI.Control(_foregroundElement); _dragControl.initialize(); } _dragControl.get_behaviors().add(_dragBehavior); _dragBehavior.initialize(); }}
But that .. didn't work. It doesn't really do anything, so I'm not sure what I'm doing wrong.

I dunno if this is the best forum to say this but damned i hate javascript...

I copied your code and worked for me (with bugs)...


And the modal window moves for you?


worked with some bugs... i made a thick border on the pannel...

1. it drags but doesn't get fixed
2. sometimes it doesn't show the drag but it fixes


just a note... i have the latest version of atlas control toolkit...

(every day i update from codeplex (i recommend this, but i'm not yet experienced with atlas or even ajax stuff))


Can you post your test page? I was just changing the Toolkit dll and then was loading the SampleWebsite provided with the toolkit to see if it worked or not.

In my case, doesn't work. No errors, but doesn't work.

there it goes, BUT -->> i didn't try to fix the bugs! All i did was: put your stuff into .js write aspx, press play... saw it ON THE WAY IT WAS AND DID NOTHING...

At least you will be able to see the modal popup being draged...

Good luck fixing the problems ;) needing, i'm here...

<asp:ButtonID="_showModalPopup"runat="server"Text="Show dragable modal popup!"/> <asp:PanelID="_handlePanel"runat="server"Height="281px"Width="929px"><asp:PanelID="_dragableModalPopup"runat="server"BorderStyle="Solid"BorderColor="Black"BorderWidth="8"Width="300"Height="300">

I'm a dragable modal popup!

<br/><br/><asp:ButtonID="_okButton"runat="server"Text="OK"/><asp:ButtonID="_cancelButton"runat="server"Text="Cancel"/><asp:ButtonID="_postBackTest"runat="server"Text="Make me a post back"OnClick="Button4_Click"/>

_okButton

</asp:Panel></asp:Panel><asp:LabelID="_lblTest"runat="server"Text=""></asp:Label><atlasToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"><atlasToolkit:ModalPopupPropertiesTargetControlID="_showModalPopup"PopupControlID="_dragableModalPopup"BackgroundCssClass="watermarked"OkControlID="_okButton"CancelControlID="_cancelButton"OnOkScript="okScript()"OnCancelScript="cancelScript()"ID="_modalPopupProperties"/></atlasToolkit:ModalPopupExtender><atlasToolkit:DragPanelExtenderID="DragablePanelExtender"runat="Server"><atlasToolkit:DragPanelPropertiesTargetControlID="_dragableModalPopup"DragHandleID="_handlePanel"/></atlasToolkit:DragPanelExtender>

Just a note: I used the "AtlasControlToolkit test project" wich can be found on the latest releases on codeplex.com. I'm posting the full code..

<%

@.PageLanguage="C#"MasterPageFile="~/Default.master"CodeFile="ModalPopup.aspx.cs"Inherits="Automated_ModalPopup"Title="ModalPopupTests Tests" %>

<

asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"runat="Server"><asp:ButtonID="_showModalPopup"runat="server"Text="Show dragable modal popup!"/> <asp:PanelID="_handlePanel"runat="server"Height="281px"Width="929px"><asp:PanelID="_dragableModalPopup"runat="server"BorderStyle="Solid"BorderColor="Black"BorderWidth="8"Width="300"Height="300">

I'm a dragable modal popup!

<br/><br/><asp:ButtonID="_okButton"runat="server"Text="OK"/><asp:ButtonID="_cancelButton"runat="server"Text="Cancel"/><asp:ButtonID="_postBackTest"runat="server"Text="Make me a post back"OnClick="Button4_Click"/>

_okButton

</asp:Panel></asp:Panel><asp:LabelID="_lblTest"runat="server"Text=""></asp:Label><atlasToolkit:ModalPopupExtenderID="ModalPpoupExtender1"runat="server"><atlasToolkit:ModalPopupPropertiesTargetControlID="_showModalPopup"PopupControlID="_dragableModalPopup"BackgroundCssClass="watermarked"OkControlID="_okButton"CancelControlID="_cancelButton"OnOkScript="okScript()"OnCancelScript="cancelScript()"ID="_modalPopupProperties"/></atlasToolkit:ModalPopupExtender><atlasToolkit:DragPanelExtenderID="DragablePanelExtender"runat="Server"><atlasToolkit:DragPanelPropertiesTargetControlID="_dragableModalPopup"DragHandleID="_handlePanel"/></atlasToolkit:DragPanelExtender><scripttype="text/javascript">// (c) Copyright Microsoft Corporation.// This source is subject to the Microsoft Permissive License.// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.// All other rights reserved.// Script objects that should be loaded before we runvar typeDependencies = ['AtlasControlToolkit.ModalPopupBehavior'];// Test Harnessvar testHarness =null;// Controls on the pagevar show;var popup;var ok;var cancel;var postback;var behavior;// Variablesvar msg;function okScript() {

msg =

'ok';

}

function cancelScript() {

msg =

'cancel';

}

function checkPopupNotVisible() {

testHarness.assertEqual(popup.style.display,

'none','Popup should not be visible');

}

function checkPopupVisible() {

testHarness.assertEqual(popup.style.display,

'','Popup should be visible');

}

function checkMessage(m) {

testHarness.assertEqual(msg, m,

'Message \"'+msg+'\" should be \"'+m+'\"');

}

function checkLabel(m) {var label = testHarness.getElement("ctl00_ContentPlaceHolder1_Label1").innerText;

testHarness.assertEqual(label, m,

'Label \"'+label+'\" should be \"'+m+'\"');

}

function showPopup() {

show.click();

}

function clickOK() {

ok.click();

}

function clickCancel() {

cancel.click();

}

// Register the testsfunction registerTests(harness) {

testHarness = harness;

var test;

show = testHarness.getElement(

"ctl00_ContentPlaceHolder1_Button1");

popup = testHarness.getElement(

"ctl00_ContentPlaceHolder1_Panel1");

ok = testHarness.getElement(

"ctl00_ContentPlaceHolder1_Button2");

cancel = testHarness.getElement(

"ctl00_ContentPlaceHolder1_Button3");

postback = testHarness.getElement(

"ctl00_ContentPlaceHolder1_Button4");

behavior = testHarness.getObject(

"ModalPopupProperties1");

msg =

'';

behavior.set_DropShadow(!behavior.get_DropShadow());

test = testHarness.addTest(

"Initial State");

test.addStep(

function() { checkLabel('Label1'); });

test.addStep(checkPopupNotVisible);

test.addStep(

function() { checkMessage(''); });

test = testHarness.addTest(

"Show Event/State");

test.addStep(showPopup);

test.addStep(checkPopupVisible);

test.addStep(

function() { checkMessage(''); });

test = testHarness.addTest(

"Cancel Event/State");

test.addStep(showPopup);

test.addStep(checkPopupVisible);

test.addStep(clickCancel);

test.addStep(checkPopupNotVisible,

function() {try { checkMessage('cancel');returntrue; }catch (ex) {returnfalse; } }, 100, 5000);

test = testHarness.addTest(

"OK Event/State");

test.addStep(showPopup);

test.addStep(checkPopupVisible);

test.addStep(clickOK);

test.addStep(checkPopupNotVisible,

function() {try { checkMessage('ok');returntrue; }catch (ex) {returnfalse; } }, 100, 5000);

test = testHarness.addTest(

"Script Show/Hide");

test.addStep(

function() { behavior._show(); });

test.addStep(checkPopupVisible);

test.addStep(

function() { behavior._hide(); });

test.addStep(checkPopupNotVisible);

test = testHarness.addTest(

"Postback");

test.addStep(

function() { behavior._show(); });

test.addPostBack(postback);

test.addStep(

function() { checkLabel('Button4'); });

}

</script>

</

asp:Content>


FYI, all I had to do was use the dragExtender in companion to the modal popup

<asp:Panel ID="pnlModal" run="server"> <div id="dragHandle" style="position:absolute; top:0px; left: 0px; height:30px; width:50px; cursor:hand;></div> <div> <iframe id="ifrmModal" runat="server" frameborder="0" height="100%" width="100%" /> </div> <div> <asp:Button Id="ModalOK" runat="server" Text="OK" UseSubmitBehavior="false" /> <asp:Button Id="ModalCancel" runat="server" Text="Cancel" UseSubmitBehavior="false" /> <asp:LinkButton ID="lnkModal" runat="server" Text="Click here" /> </div></asp:Panel><atlasToolkit:ModalPopupExtender ID="mpe1" runat="server"> <atlasToolkit:ModalPopupProperties ID="pnlModalBehavior" BackgroundCssClass="modalBackground" DropShadow="false" OkControlID="ModalOK" PopupControlID="pnlModal" TargetControlID="lnkModal" /></atlasToolkit:ModalPopupExtender><atlasToolkit:DragPanelExtender ID="dragPanelExtender1" runat="server"> <atlasToolkit:DragPanelProperties TargetControlID="pnlModal" DragHandleID="dragHandle" /> </atlasToolkit:DragPanelExtender>

KFrancis,

Just adding the DragPanelExtender works -- except if the modal popup has a drop shadow. The drop shadow does not move along with the modal popup window.

Any ideas on how to fix that?

Thanks,

Randall Price


yea, remove the drop shadow.

Hi KFrancis,

I copy&paste your code and it works. But I found one thing really weird is that if I add the quotation mark for the <style='...> property, it's no longer draggable!! (The quotation mark should be there, right?)

<div id="dragHandle" style='position:absolute; top:0px; left: 0px; height:30px; width:50px; cursor:hand;></div>

I'm using July CTP, any idea why this is happening?

And even when it's draggable, the popup won't show up at the center of page. The initial location has shifted to the right bottom. Do you know how to fix this?

Wednesday, March 21, 2012

How can I stop the modal popup from disappearing when a postback occurs?

Hello,

I have a problem.
How can I stop the modal popup from disappearing when a postback occurs.

For example, if I have a button on the modal "form", a click makes it dissappear.

Help!

Thanks!

UPDATE:
I just tried wrapping the postback controls in an updatepanel.

Seems to work so far...this the recommended way?

How can I see ModalPopup js code ?

I'm a big fan of the modal popup extender and I'm trying to implement it using plain DHTML since my client have no asp.net server and I'm using classic ASP.

As you know, there is a classic IE annoying bug with COMBO BOXES. They stay on top of every div, without respecting the z-index layout.

I'm interested in learning how the Ajax Control Toolkit programmers handled this situation so I can do the same.

I can't just hide the combos, since I'm usiing a transparent Modal Background and I wish I could see the combos BEHIND the Modal Background.

Thanks!

Hi,

You can download the source codehere. Its implementation can be found in ModalPopupBehavior.js file.


thanks

How can I open Modal Popup from code behind

I have a page that on load builds a datatable base on the users userid.

An if else statment detemrines whetehr or not the user simply proceeds or else has to make a selection prior to proceeding.

So there is no control to open the modal popup from like a button click...and whats more not EVERY person accessing the window will get the modal popup.

I assume there is a way in the code behind that I can fire up the Modal Popup as a condition of the else...

any help would be appreciated.

Call the show method.

ModalPopupExtender1.show()

How can I get this ModalPopupExtender to work with Master Pages?

Here's some pretty simple code that displays a modal pop-up when a button is pressed:

1<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="5_UpdateProgModal.aspx.cs" Inherits="_5_UpdateProgModal" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml">
5<head runat="server">
6 <title>ASP.Net AJAX 201</title>
7 <style type="text/css">
8 .error{color: #f00;}
9 .message{color: #000;}
10 .updating{margin: 12px;}
11 .modalBackground
12 {
13 background-color:#00f;
14 filter:alpha(opacity=40);
15 opacity:0.40;
16 }
17 .updateProgress
18 {
19 border: solid 1px #333;
20 background-color:#fff;
21 position:absolute;
22 text-align: center;
23 width:160px;
24 height:60px;
25 }
26 .updateProgressMessage
27 {
28 margin:3px;
29 vertical-align: middle;
30 }
31 </style>
32</head>
33<body>
34 <form id="form1" runat="server">
35 <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="3" />
36 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
37 <ContentTemplate>
38 <div>
39 <asp:Button ID="btnShowTime" runat="server" Text="Show Time" OnClick="btnShowTime_Click" />
40 <asp:Button ID="btnError" runat="server" Text="Throw Error" OnClick="btnError_Click" />
41 <asp:Button ID="btnTimeout" runat="server" Text="Timeout" OnClick="btnTimeout_Click" />
42 </div>
43 <div>
44 <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
45 </div>
46 </ContentTemplate>
47 </asp:UpdatePanel>
48 <asp:Panel ID="pnlProg" runat="server" CssClass="updateProgress" style="display:none">
49 <div class="updating">
50 <img src="images/ajax-loader.gif" alt="Processing..." />
51 <span class="updateProgressMessage">Processing...</span>
52 </div>
53 </asp:Panel>
54 <AjaxToolkit:ModalPopupExtender
55 ID="mdlProgress"
56 runat="server"
57 TargetControlID="pnlProg"
58 PopupControlID="pnlProg"
59 BackgroundCssClass="modalBackground"/>
60 </form>
61 <script type="text/javascript">
62 var prm = Sys.WebForms.PageRequestManager.getInstance();
63 prm.add_beginRequest(beginRequest);
64 prm.add_endRequest(endRequest);
65
66 function beginRequest(sender, args)
67 {
68 $find("mdlProgress").show();
69 }
70
71 function endRequest(sender, args)
72 {
73 $find("mdlProgress").hide();
74
75 var messageSpan = $get("<%= lblMessage.ClientID%>");
76 if (args.get_error() != undefined)
77 {
78 var errorMessage = args.get_error().message;
79 if (args.get_error() && args.get_error().name === 'Sys.WebForms.PageRequestManagerTimeoutException') {
80 errorMessage = "Your operation has timed out.";
81 }
82 args.set_errorHandled(true);
83 messageSpan.className = "error";
84 messageSpan.innerHTML = errorMessage;
85 }
86 }
87 </script>
88</body>
89</html>
90

The code behind for the buttons just does a Threading.Sleep() for testing purposes so I'm not going to bother posting that code.

The problem is, I want to use this in a master page... However, when I put all this code in my master page, it doesn't work. I end up getting Javascript errors that I can't figure out. Any ideas as to why the above code works perfect yet won't work in a master page?

Hi,

Change

$find("mdlProgress")

to:

$find("<%=mdlProgress.ClientID%>")

Then, no matter master page or page, it works!

Best Regards,


The code posted by you is simple and handy and I like its simplicity for quick trials..


That was it.

I figured it was my lack of Javascript knowledge. :) Thanks so much!