i got an user management page in my .net vb web application where an admin is able to enable/disable users, rename, change passwords and so on. This changes are applied in sql then.
While i was developing that i simply used .net vb message boxes, now i want to polish my website's appearance a bit so first i thought about replacing all messageboxes with javascript alerts() but that was not enough... so i decied to try something new (for
me!).
I found some solutions where people created a <div> (sometimes as a server control) and made it visible with some buttons - but i wasn't able find out how they actually do a postback or whatever to update the divs attributes (visibility, position...)
In my case i got an gridview with some image buttons where my user actions are. for example if an admin tries to disable himself he should get a popup telling him that this is not possible and so on.
I am already using ajax script mangers and updatepanels - is it possible to accomplish this that way?
If you want to show or hide using div popoup than its good if you will do it with JQuery and you can manage it easily.
Add Jquery files and do as below way.
Here I am attaching sample how to open and hide this.
So one button on which you want to open than add this code on event of that button which will open the dialog box
Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "null", "Showdialog();", true);
Please check it and let me know if you have any query.
NH Kariya Software Professional
Please remember to click “Mark as Answer” on the post that helps you
showPopup("You cannot delete the user you are currently logged in with!", False, "ok")
'shows a modal popup'
Protected Sub showPopup(ByVal message As String, ByVal showNo As Boolean, Optional ByVal yesCaption As String = "Yes", Optional ByVal noCaption As String = "No")
'enable / disable buttons'
If (showNo) Then
bt_no.Visible = True
bt_no.Enabled = True
bt_no.Text = noCaption
Else
'just show yes'
bt_yes.Visible = True
bt_yes.Enabled = True
bt_yes.Text = yesCaption
bt_no.Visible = False
bt_no.Enabled = False
End If
'set label message'
l_msg.Text = message
'show popup'
Me.MPE.Show()
End Sub
When I remove bt_dummy's css display attribute and click the button everything works just fine, but when I leave the button hidden and click the gridview's imagebutton and the sub "showPopup" is called an Jscript error appears:
Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements
on this position:
var e = Function._validateParams(arguments, [
{name: "elements"},
{name: "eventName", type: String},
{name: "handler", type: Function},
{name: "autoRemove", type: Boolean, mayBeNull: true, optional: true}
]);
if (e) throw e;
'enable / disable buttons'
If (showNo) Then
bt_no.Style.Item(HtmlTextWriterStyle.Display) = vbNullString
bt_no.Enabled = True
bt_no.Text = noCaption
Else
'just show yes'
bt_yes.Visible = True
bt_yes.Enabled = True
bt_yes.Text = yesCaption
bt_no.Style.Item(HtmlTextWriterStyle.Display) = "none"
bt_no.Enabled = False
End If
thats the way hiding buttons! because i set the button visible = false javascript couldn't find it and threw an error! damn it - that took me 3 hours finding such a simple mistake.
Schweindi
Member
2 Points
11 Posts
Using a div popup instead of messagebox
Jan 23, 2013 12:14 AM|LINK
Hi,
i got an user management page in my .net vb web application where an admin is able to enable/disable users, rename, change passwords and so on. This changes are applied in sql then.
While i was developing that i simply used .net vb message boxes, now i want to polish my website's appearance a bit so first i thought about replacing all messageboxes with javascript alerts() but that was not enough... so i decied to try something new (for me!).
I found some solutions where people created a <div> (sometimes as a server control) and made it visible with some buttons - but i wasn't able find out how they actually do a postback or whatever to update the divs attributes (visibility, position...)
In my case i got an gridview with some image buttons where my user actions are. for example if an admin tries to disable himself he should get a popup telling him that this is not possible and so on.
I am already using ajax script mangers and updatepanels - is it possible to accomplish this that way?
thank you for ideas and any help!
anuj_koundal
Contributor
2088 Points
496 Posts
Re: Using a div popup instead of messagebox
Jan 23, 2013 03:02 AM|LINK
use ModalPopUpExtender
Regards
Anuj Koundal
nhkariya
Member
72 Points
11 Posts
Re: Using a div popup instead of messagebox
Jan 23, 2013 03:09 AM|LINK
Hello,
If you want to show or hide using div popoup than its good if you will do it with JQuery and you can manage it easily.
Add Jquery files and do as below way.
Here I am attaching sample how to open and hide this.
<table id="dialog-form" width="100%" border="0" cellspacing="2" cellpadding="5" class="label" title="Details form"> <tr> <td align="right" width="25%"> Name <span class="mandatory">*</span> </td> <td align="left"> <asp:TextBox ID="txtTest" runat="server" Width="210px" TabIndex="1" MaxLength="50"></asp:TextBox> </td> </tr> <tr> <td> </td> <td align="left" valign="bottom"> <asp:Button Text="SUBMIT" ID="btnSubmit" runat="server" ValidationGroup="Submit" class="s_but" TabIndex="3" OnClick="btnSubmit_Click" /> <asp:Button Text="CANCEL" ID="btnCancel" runat="server" class="s_but" TabIndex="4" /> </td> </tr> </table> <script type="text/javascript"> $(function () { $("#dialog-form").dialog({ autoOpen: false, height: 500, width: 700, modal: true, resizable: false, open: function (type, data) { $(this).parent().appendTo("form"); } }); $("#<%=btnCancel.ClientID %>") .click(function () { $("#dialog-form").dialog("close"); return false; }); }); function Showdialog() { $(function () { $('#dialog-form').dialog('open'); }); } </script>So one button on which you want to open than add this code on event of that button which will open the dialog box
Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "null", "Showdialog();", true);
Please check it and let me know if you have any query.
Please remember to click “Mark as Answer” on the post that helps you
Schweindi
Member
2 Points
11 Posts
Re: Using a div popup instead of messagebox
Jan 23, 2013 04:35 PM|LINK
thank you both!
I'll start with the ajax solution, as I am already using AJAX.
I'll report back when I got something working.
UPDATE ***:
Okay I added an modalpopupextender to my page:
<asp:ModalPopupExtender ID="MPE" runat="server" BackgroundCssClass="popup_background" CancelControlID="bt_no" DropShadow="True" OkControlID="bt_yes" TargetControlID="bt_dummy" PopupControlID="popup" Drag="True" PopupDragHandleControlID="popup"> </asp:ModalPopupExtender>an bt_dummy (as i want to show the popup from codebehind:
and finally my panel:
<asp:Panel ID="popup" runat="server" BackColor="Red" Height="269px" Width="400px" Style="display: none; cursor: move;"> <table width="100%" style="border: Solid 3px #D55500; width: 100%; height: 100%" cellpadding="0" cellspacing="0"> <tr style="background-color: #FFFFFF"> <td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger" align="center"> <asp:Label ID="L_msg" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td> <asp:Button ID="bt_yes" runat="server" Text="Yes" /> <asp:Button ID="bt_no" runat="server" Text="No" /> </td> </tr> </table> </asp:Panel>and code behind:
showPopup("You cannot delete the user you are currently logged in with!", False, "ok") 'shows a modal popup' Protected Sub showPopup(ByVal message As String, ByVal showNo As Boolean, Optional ByVal yesCaption As String = "Yes", Optional ByVal noCaption As String = "No") 'enable / disable buttons' If (showNo) Then bt_no.Visible = True bt_no.Enabled = True bt_no.Text = noCaption Else 'just show yes' bt_yes.Visible = True bt_yes.Enabled = True bt_yes.Text = yesCaption bt_no.Visible = False bt_no.Enabled = False End If 'set label message' l_msg.Text = message 'show popup' Me.MPE.Show() End SubWhen I remove bt_dummy's css display attribute and click the button everything works just fine, but when I leave the button hidden and click the gridview's imagebutton and the sub "showPopup" is called an Jscript error appears:
on this position:
var e = Function._validateParams(arguments, [ {name: "elements"}, {name: "eventName", type: String}, {name: "handler", type: Function}, {name: "autoRemove", type: Boolean, mayBeNull: true, optional: true} ]); if (e) throw e;arguments:
null, 'click', <an function>
what's up here?
Schweindi
Member
2 Points
11 Posts
Re: Using a div popup instead of messagebox
Jan 23, 2013 11:53 PM|LINK
Oh my god! i am stupid as hell!
'enable / disable buttons' If (showNo) Then bt_no.Style.Item(HtmlTextWriterStyle.Display) = vbNullString bt_no.Enabled = True bt_no.Text = noCaption Else 'just show yes' bt_yes.Visible = True bt_yes.Enabled = True bt_yes.Text = yesCaption bt_no.Style.Item(HtmlTextWriterStyle.Display) = "none" bt_no.Enabled = False End Ifthats the way hiding buttons! because i set the button visible = false javascript couldn't find it and threw an error! damn it - that took me 3 hours finding such a simple mistake.