8

What I am trying to do is create a bit of reusable code that can write a modal popup, either through javascript or using the ajaxcontrol toolkit all from the code behind.

The modal would be a sort of login pop up for controlling access to more restricted areas of the website allowing certain users to re-credential in for higher access.

I was thinking of doing a user control but I forsee some problems with passing all of the appropriate information along without it being completely hoaky.

If anyone has any good links or advice for doing so it would be greatly appreciated!

Thanks!

EDIT: I know how to use the ajax control toolkit and its controls, and I know how to make login screens, I'm asking how to do this entirely from the code behind from a class that would be independent of its implementation

Jimmy
  • 9,686
  • 14
  • 59
  • 78
  • I don't want to type my credentials in again. Couldn't you just give me an admin role and handle the authorization in your code? – DOK Jan 06 '10 at 13:52
  • @DOK: There are scenarios where the business dictates that the user needs to provide the credentials again as some sort of digital sign-off. This is quite common in medical/clinical systems. – Wim Jan 06 '10 at 13:56
  • Wim hit the nail on the head, health care programming :D – Jimmy Jan 06 '10 at 13:57

5 Answers5

3

Write a server control or an asp.net extender control like ajax control toolkit does.

The best you can do is download the source of AjaxControlToolkit from CodePlex and explore the source of ModalPopup within that.

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137
  • didn't think about this, will look into it – Jimmy Jan 06 '10 at 13:58
  • this is looking pretty promising, thanks a lot, I'm using the following tutorial and so far so good: http://www.asp.net/learn/Ajax-Control-Toolkit/tutorial-49-cs.aspx – Jimmy Jan 06 '10 at 14:44
2

Another thing you can do is just simply call the popupExtender to show from the code behind file. As we know the extender has to be somehow linked to a target control, just add a dummy control as a hidden textbox (actually to hide the control, do it from the asp file, as style="display:none" not from the control properties (visible=false) otherwise it won't work), and then just call from the code behind the extender like this:

DummyTextBox_ModalPopupExtender.Show();

You can call it in the page_load or with anyother trigger.

No need javascript neither client side, just, server side. Xds.

Xds
  • 21
  • 2
0

Add BehaviorID="my_cool_id" to your modalpopup extender and add this to any server function

ScriptManager.RegisterStartupScript(Page, this.GetType(),"id","function pageLoad(){$find('my_cool_id').show();}",true);
LazyZebra
  • 1,097
  • 16
  • 24
0

There's a sample modal popup using the ajaxtoolkit on asp.net

stuartd
  • 70,509
  • 14
  • 132
  • 163
0

The modalpopupextender in the Ajax control toolkit is easy to use, plus it has a server or client side method for showing the popup (in past versions, I had trouble with the server-side method, but it may have been resolved in the current version).

You could put the modalpopupextender inside the master page, and create a JS method in the master page you can call to invoke the modal popup extender, like:

function showPopup() { var modal = $find("<%= mpe1.ClientID %>"); modal.show(); }

The contents of the popup can be replaced via javascript, as you control that content.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257