Ajax modal popup position on small screens - asp.net

I have the following modal popup on a Asp.net/C# web application. The modal popup holds multiple placeholders. My problem occurs when I am trying to access the modal popup on small screens or on ipad/iphone/ipod screens. The page display the half of the modal popup so the information in the top are inaccessible. I have used overflow:auto;/ the following solution: Mobile ModalPopupExtender? and many others but doesn’t solved my problem.
.modalBackground {
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7; } .modalPopup {
background-color:#ffffdd;
border-width:3px;
border-style:solid;
border-color:Gray;
padding:3px;
width:250px; }
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" PopupDragHandleControlID="Panel1" RepositionMode="None" runat="server" PopupControlID="pnlpopup"
TargetControlID="btnShowPopup" CancelControlID="btnCancel"
DropShadow="true"
BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="LightGray" style="display:none;"
CssClass="modalPopup" Width="650px" >
<asp:UpdatePanel ID="UpdatePanel3" UpdateMode="Conditional" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnCancel" Height="30px" Width="160px" runat="server" Text="Cancel" />
</asp:Panel>

#focus: As I am using Jquery to attach ModalPopup to a button but code I used to check innerheight and then add class to my panel is:
var height = window.innerHeight;
if (height < 1000) {
$("#pnlpopup").addClass("PanelWithScroll");
}
You need to add above code in javascript and this need to be called on ModalPopupExtender click.
PanelWithScroll is a css class:
.PanelWithScroll{
height:250px;
overflow:scroll;
overflow-x:hidden;
}
Similarly, if you have problem with width too, you can check width too (http://responsejs.com/labs/dimensions/) and change class PanelWithScroll
Other thing you can do is check page height on page_load and if its less than what you want, add this class to pnlpopup Div. (This is easy solution IMO)
Update:
Add given javascript in your HTML Code in head section
$(document).ready(function () {
var height = window.innerHeight;
if (height < 1000) {
$("#pnlpopup").addClass("PanelWithScroll");
}
}
$(document).ready will only run after your page has wholly rendered. This may also help if you need help on how to put script in html (http://javascript.info/tutorial/adding-script-html)

Related

ASPX Page formatting

I have Panel that needs to have a button beside it but have been unsuccessful in formatting it. Currently this is what I have.
<asp:Panel runat="server" CssClass="form" ID="panSomeParameters"></asp:Panel>
<asp:Button runat="server" CssClass="form" ID="btnSomeButton" Text="Button" />
Basically I need the Button in the blue area.
You just need to set your Panel display to "inline-block" as panel is rendered as Div and div is a block element so it will cover the whole row. I have set width and height also so panel will contain space on the view.
<asp:Panel runat="server" style="display:inline-block;width:100px;height:20px;" CssClass="form" ID="panSomeParameters"></asp:Panel>
<asp:Button runat="server" CssClass="form" ID="btnSomeButton" Text="Button" />
If it helps then accept the Answer.
You could give them both a class and set the float to left.
<div>
<asp:Panel ID="Panel1" runat="server" CssClass="float-left">
Contents
</asp:Panel>
<asp:Button ID="Button1" runat="server" Text="Button" CssClass="float-left" />
</div>
<style>
.float-left {
float: left;
}
</style>

Ajax modalpopupextender not popping up

.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.modalPopup
{
background-color: #ddffdd;
border-width: 3px;
border-style: solid;
border-color: Gray;
margin-top: 60px;
padding: 2px;
width: 400px;
font-size: 10pt;
}
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="Button3"
OkControlID="btnOk" TargetControlID="LinkButtonDummy" PopupControlID="PanelPopUp"
BackgroundCssClass="modalBackground" />
<asp:Panel ID="PanelPopUp" runat="server" CssClass="modalPopup" Style="display: none">
<div>
<asp:Label ID="lblMsg" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Add New Organisation" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Cancel" />
</div>
</asp:Panel>
I have also included the AJAX reference and a ScriptManager on the master page.
I have to add an enhancement to an existing page and I'm quite new with ASP.NET, the page in question is a 'content page' and is linked to a master page (containing the scriptmanager).
This code all looks completely fine and I have been reading on this for over three hours now but to no avail - my modal doesn't 'pop-up' and grey the background out, it simply appears where I have placed it on the page (right at the top, or right at the bottom e.t.c.) as if I was just showing/hiding a div.
Can anyone help, I'm going crazy?
What other routes can I go down for adding a confirmation box on a page that takes a string built in the code-behind and also runs code-behind functions on OK/Cancel?
Keep your css as it it and try this code :
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:ModalPopupExtender ID="MyPopup" runat="server" CancelControlID="Button3" OkControlID="btnOk" PopupControlID="PanelPopUp" BackgroundCssClass="modalBackground" DynamicServicePath="" Enabled="True"
TargetControlID="HiddenField1"></asp:ModalPopupExtender>
and on Button2_Click event add
MyPopup.Show();

ASP.NET ajaxcontroltoolkit autocomplete ul overlay issue

I have a following snippet of code in my ASP.NET application (simplified):
<asp:Panel ID="Panel7" runat="server">
<asp:TextBox ID="RecTextBox" runat="server" autocomplete="off" Height="18px" Width="800px"/>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
CompletionListCssClass="autocomplete_completionListElements"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
CompletionListItemCssClass="autocomplete_listItem"
CompletionSetCount="20"
DelimiterCharacters=";, :"
Enabled="True"
MinimumPrefixLength="2"
ServiceMethod="GetCompletionList"
ServicePath="Rec.asmx"
ShowOnlyCurrentWordInCompletionListItem="True"
TargetControlID="RecTextBox" />
<br />
<asp:Button ID="Button3" runat="server" Text="Add" OnClick="Button3_Click" />
<asp:Button ID="Button11" runat="server" Text="Remove" OnClick="Button11_Click" />
<br />
<asp:Panel ID="Panel8" runat="server" Height="150">
<asp:ListBox ID="ListBox1" runat="server" Width="800" Height="150"></asp:ListBox>
</asp:Panel>
</asp:Panel>
Along with CSS classes:
.autocomplete_completionListElements
{
overflow : auto;
height : 130px;
list-style-type : none;
}
/* AutoComplete highlighted item */
.autocomplete_highlightedListItem
{
background-color: #ffff99;
color: black;
padding: 1px;
}
/* AutoComplete item */
.autocomplete_listItem
{
background-color : window;
color : windowtext;
padding : 1px;
left :0px
}
The problem is that autocomplete plugin renders an unordered list. It is contained in the document if autocomplete list is visible or not:
<ul id="ContentPlaceHolder2_TabContainer1_TabPanel2_AutoCompleteExtender1_completionListElem" class="autocomplete_completionListElements" style="position: absolute;"></ul>
When the autocomplete list is visible, there is no problem, because user is able to select desired autocomplete element. In turn autocomplete list is hidden, the unordered list is invisible but overlays multi select HTML controls (because ul has height : 130px;), and there are problems with selecting elements inside the multiselect:
Problem occurs in FF and Opera, but not in IE and Chrome.
Please for help,
Best regards,
WP
I found one possible solution based on Javascript:
1) Modify autocomplete_completionListElements CSS class - remove height : 130px; property.
.autocomplete_completionListElementy
{
overflow : auto;
list-style-type : none;
}
2) Assign Javascript handlers to following AutoCompleteExtender properties: OnClientShown, OnClientHidden
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
CompletionListCssClass="autocomplete_completionListElements"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
CompletionListItemCssClass="autocomplete_listItem"
CompletionSetCount="20"
DelimiterCharacters=";, :"
Enabled="True"
MinimumPrefixLength="2"
ServiceMethod="GetCompletionList"
ServicePath="Rec.asmx"
ShowOnlyCurrentWordInCompletionListItem="True"
TargetControlID="RecTextBox"
OnClientShown="autocompleteClientShown"
OnClientHidden="autocompleteClientHidden" />
3) Javascript handlers code:
function autocompleteClientShown(source, args) {
source._popupBehavior._element.style.height = "130px";
}
function autocompleteClientHidden(source, args) {
source._popupBehavior._element.style.height = "0px";
}

ASP.NET Form inside a Hidden Div won't work

I have a login FORM inside a Hidden DIV, this DIV is hidden using CSS display:none; when I click on some other DIV, I show this DIV using jquery .slideDown(), so I can be able to use this form.
When I click on the button, the OnClick="Login" doesn't seem to work,and when I removed this form from this hidden div to simply another place in the body, it worked. What's the problem?
ASP.NET:
<div id="userCPContainer">
<form id="loginForm" runat="server">
<asp:Label ID="Label1" runat="server" Text="Username" class="loginLabels"></asp:Label>
<br />
<asp:TextBox ID="usernameField" runat="server" MaxLength="50" class="loginFields"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Password" class="loginLabels"></asp:Label>
<br />
<asp:TextBox ID="passwordField" runat="server" MaxLength="50"
TextMode="Password" class="loginFields"></asp:TextBox>
<asp:Button ID="loginButton" runat="server" Text="Log in" onclick="Loginn" class="loginButton"/>
</form>
</div>
JQUERY:
function showUserCP() {
$("#userCPContainer").slideDown(200);
$(".userCPDiv").css("background-color", "#000000");
$(".userCPDiv").css("border-color", "#000000");
}
function hideUserCP() {
$(".userCPDiv").css("background-color", "rgb(43, 147, 206)");
$(".userCPDiv").css("border-color", "rgb(43, 147, 206)");
$("#userCPContainer").slideUp(200);
}
$(".userCPDiv").click(function (e) {
//Either way, hide Main Menu
hideMainMenu();
if ($("#userCPContainer").is(":visible")) {
hideUserCP();
}
else {
showUserCP();
}
e.stopPropagation();
});
CSS:
#userCPContainer
{
overflow:hidden;
border-style:solid;
border-top-style:none;
border-color:rgb(43,147,206);
border-width:2px;
position:absolute;
right:0px;
top:0px;
display:none;
z-index:1;
width:300px;
background-color: #000000;
}
Nothing really complicated...
When you use CSS display: none; the problem is that all that's inside that DIV gets removed completely from the HTML Document and that causes that ASP.NET does not recognize this element when you show it via jQuery. I see to possible solutions:
Use visibility: hidden instead of display: none;, if you do this you will probably have some problems with the DIV height because it will take the space needed to render but it will not be visible.
Use a ScriptManager and an UpdatePanel and put the div and the form inside those elements, so the server will know when you render the Button in the client. Also, make sure that you register your jQuery scripts inside the ScriptManager
Hope this helps you

How to get the id of Updatepanel which initiated a postback

Hi I need to intercept server callback after udate panel async post back and determine which panel initiated the request. The code is pretty simple:
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InterceptUpdateCallback);
function InterceptUpdateCallback(sender, args)
{
var updatedPanels = args.get_panelsUpdated();
for (idx = 0; idx < updatedPanels.length; idx++) {
if (updatedPanels[idx].id == "myUpdatePanel") {
StartSmth();
break;
}
}
}
And it works when UpdatePanel is not inside another UpdatePanel. But when it is inside another UpdatePanel updatedPanels[idx].id has parent Updatepanel id. So how can I get the id of UpdatePanel which initiated the request (the inner UpdatePanel)? Thanx
Here you go:
function InterceptUpdateCallback(sender, args) {
if (sender._postBackSettings)
alert(sender._postBackSettings.panelID);
else
alert('first load');
}
Update:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void LinkButtons_Click(object sender, EventArgs e)
{
LabelMain.Text = LabelSub1.Text = LabelSub2.Text = LabelSub3.Text = string.Format("{0} Updated By {1}", DateTime.Now, ((Control)sender).ID);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
body { font-family: Tahoma;}
fieldset { padding: 15px; }
fieldset a
{
float: right;
clear: none;
display: block;
margin: 10px;
}
fieldset span
{
display: block;
margin-top: 20px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script type="text/javascript">
function pageLoaded(sender, args) {
if (sender._postBackSettings) {
var panelId = sender._postBackSettings.panelID.split('|')[0];
if (panelId == sender._scriptManagerID) {
var updatedPanels = args.get_panelsUpdated();
var affectedPanels = "Affected Panels:\n";
for(var x=0;x<updatedPanels.length;x++)
affectedPanels+= updatedPanels[x].id + "\n";
alert("Request initiated by ScriptManager\n\nMight be an async trigger, or child of an update panel with children as triggers set to false.\n\n"+affectedPanels);
}
else
alert("Request initiated by: " + panelId);
}
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
</script>
<asp:LinkButton ID="UpdateMain" runat="server" Text="UpdateMain" OnClick="LinkButtons_Click"></asp:LinkButton>,
<asp:LinkButton ID="UpdateSub1" runat="server" Text="UpdateSub1" OnClick="LinkButtons_Click"></asp:LinkButton>,
<asp:LinkButton ID="UpdateSub2" runat="server" Text="UpdateSub2" OnClick="LinkButtons_Click"></asp:LinkButton>,
<asp:LinkButton ID="UpdateSub3" runat="server" Text="UpdateSub3" OnClick="LinkButtons_Click"></asp:LinkButton>
<br />
<br />
<asp:UpdatePanel ID="Main" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:LinkButton ID="LinkButton1" runat="server" Text="LinkButton1" OnClick="LinkButtons_Click"></asp:LinkButton>
<legend>Main - Update Mode:Conditional, Children As Triggers:False</legend>
<asp:Label ID="LabelMain" runat="server" Text="LabelMain"></asp:Label>
<asp:UpdatePanel ID="Sub1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<fieldset>
<asp:LinkButton ID="LinkButton2" runat="server" Text="LinkButton2" OnClick="LinkButtons_Click"></asp:LinkButton>
<legend>Sub1 - Update Mode:Always, Children As Triggers:True</legend>
<asp:Label ID="LabelSub1" runat="server" Text="LabelSub1"></asp:Label>
<asp:UpdatePanel ID="Sub2" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
<ContentTemplate>
<fieldset>
<asp:LinkButton ID="LinkButton3" runat="server" Text="LinkButton3" OnClick="LinkButtons_Click"></asp:LinkButton>
<legend>Sub2 - Update Mode:Always, Children As Triggers:True</legend>
<asp:Label ID="LabelSub2" runat="server" Text="LabelSub2"></asp:Label>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateSub2" />
</Triggers>
</asp:UpdatePanel>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateSub1" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="Sub3" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<asp:LinkButton ID="LinkButton4" runat="server" Text="LinkButton4" OnClick="LinkButtons_Click"></asp:LinkButton>
<legend>Sub3 - Update Mode:Conditional, Children As Triggers:False</legend>
<asp:Label ID="LabelSub3" runat="server" Text="LabelSub3"></asp:Label>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateSub3" />
</Triggers>
</asp:UpdatePanel>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UpdateMain" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
I will have a guess at this one.
Does setting UpdateMode = Conditional on the outer (or both) UpdatePanels help? I think the problem is that you only get the "outermost" updated panel and if you do not set UpdateMode to Conditional the outer Panel is updated as well (even if you click something in the inner panel; see second reference).
For reference see
Note that, if I remove the property
UpdateMode=Conditional for the
UpdatePanel1 (parent), both the labels
will get refreshed.
from ASP.NET 2.0 AJAX Extensions Update Panel - Nested Update Panel
and
When set to Always, the UpdatePanel is
updated on every postback raised from
anywhere in the page, so from controls
inside the panel, inside other panels
or just on the page.
from Remember to set UpdatePanel's UpdateMode to Conditional
Finally I came to solution: the problem was that I had trigger control (Button) for child UpdatePanel which actually was outside this Update panel and inside parent UpdatePanel (sorry I hadn't noticed that). If you put Button inside child UpdatePanel - everything works fine.

Resources