i am using jquery context menu on a div inside an update panel. i read that i should be using ScriptManager.RegisterStartupScript to register the script, and that is what i did.
on partial post back the menu appears on the screen even without right clicking on the div. Moreover if i issued a right click on the div the contextMenu is launched as it normally would.
This sounds like just a styling issue, you need to specifyin your CSS that the contextMenu is hidden by default, otherwise it'll work, but also show up before you clicked to show it, which is what you describe.
If the menu is for example this:
<div class="contextMenu">.....</div>
Make sure you have corresponding CSS to hide it, like this:
.contextMenu { display: none; }
This will keep it hidden until you right click to show it :)
Related
I am new to the ASP.NET world and I need to do a popup to select some data.
The idea is that the user can select one or more options with a CheckBox. When he presses a button a popup appears with a list of options loaded from the database.
I don't know how to create a popup with those options and receive the selected options when the popup close. But I know how to do the option list from the database with a repeater.
there is no such popup control in ASP.NET.
However there are numerous 3rd party plugins, which provide popup controls.
ajax tool kit model popup extender
jquery built popups
you can create your own. popup is nothing but a hidden container, which appears upon some action, and whose location and background is as per your choice.
create a popup like this:
<div class="parent">
<div class="popup">
</div>
</div>
<input type="button" value="popup" id="btnpopup" />
and css
.parent
{
position:relative;
background-color:#CCCCCC;
width:200px;
height:200px;
}
.popup
{
width:50%;
height:50%;
position:relative;
top:20%;
left:20%;
background-color:#DDDDDD;
display:none;
}
and jQuery code
$('#btnpopup').click(function(){
$('.popup').toggle(200);
});
see this fiddle
You can use the OnClientClick of the button to open the popup. Depending on it being a normal browser popup or a jQuery dialog you have two general options:
Standard Popup
Standard popups open as if they are a separate page. When you click OK you may have to store the selection into the user's session if the data is needed on the page that triggered the popup, or store it directly in the database. If the former is the case, when you return to the page and submit it, the data from the popup will be available in the session to process.
jQuery Dialog or particularly any js-triggered html dialog. You can show it with the corresponding js again in the OnClientClick function, and perform the selection. On the OK button click of the dialog almost nothing is needed (except hiding it). Since the dialog input controls are part of the page, they will be posted on submit and be process-able on the server.
That's basically all you need to do, but some more reading on the topic won't hurt. Good luck.
I have an asp.net page with 4 tab controls using the following html for each (changing their ID's for each one etc):
<ul id="ulTabs">
<li class="displayItem" id="liSummary" style="display: block"><a ref="#divSummary">
<span style="font-weight: bold; color: #4b6c9e">Margin Analysis Summary</span>
</a></li></ul>
The problem I have is that, on two of the tabs I have GridViews that open a new modal/screen. When this modal/screen is then closed, the page refreshes and the focus automatically goes back to the first tab regardless of which tab was selected when the modal/screen was opened.
Any ideas on how I can keep focus set to the current tab? I've tried a few solutions on different links but have found nothing so far.
Store the ID of the currently opened tab in a HiddenField when the tab opened is changed.
Then on load (after the refresh) open the tab represented by the ID stored in the hidden field.
I've done this with javascript and jquery when I've used jquery tabs in the past and it works really well. In fact, if it helps, here's how to do it with jquery. I'm sure you'll be able to adapt it for your own needs (or if you're doing it all in the code behind the page then it'll be even easier).
I have an Index.aspx with a button inside which that button will call a controller, doing some logic and returning to a PartialView control - let's named it PopUpPartialView.ascx (as a popup). So to make it clear, the popup windows(PopUpPartialView) actually stays ON the top of Index.aspx when user clicks on the button.
In PopUpPartialView.ascx, there is another button, that returns say a GenerateList and now the problem is - how do I pass the thing back to the same popup windows in PopUpPartialView.ascx on the top of Index.aspx as it was before? How should my controller codes look like?
Here's what I have on the return:
return PartialView("PopUpPartialView", GenerateList);
this clearly NOT working as what I want, because it doesn't point back to Index page. I was thinking perhaps to use ajax so that I could stay on that popup ascx page. Confused~~ Someone please guide me.
Thanks.
My advice is to use a plugin which handles all the popup plumbing for you.
My poison of choice is jqModal.
It's very easy to work with - essentially a hidden container on the page, and you can load contents in there either on the initial render, or on a click event via AJAX.
So in your example, you could handle the button event click, show the dialog and load the contents of your partial view into the hidden container.
I'm currently using System.Windows.Forms webbrowser control to automate a webpage. Everything works fine to manipulate the htmlelement through webbrowser.document. However unfortunately i have to click a button which is embedded in a hidden div. so my question is, how should i turn this div 's visibility to visible and click on the button in it?
This is the div which is visible after it has been turned into visible:
<div class="box" style="visibility:visible">
<button />
</div>
Ps: the div doesn't have id but only class name (so i think it is dealing with css style)
Since i'm not able to detect with webbrowser.document , how can i retrieve it ? or how can i change the css of class = box using webbrowser.document?
Try:
yourWebBrowserControl.Document.All["YourButton"].InvokeMember("click");
If I can ask for a bit of clarification: what are you trying to accomplish?
The webbrowser control essentially encapsulates the IE rendering engine and allows you to navigate to a document or URI. When you click this button, are you navigating somewhere? Or is this a form to be submitted?
The Scenario: I have an asp.net website where I show a div popup on page load for taking a few user details. When a user inputs the details, or closes the popup, I set up a flag cookie so that the popup is not displayed again for the user. The div is in the MasterPage so that it is displayed no matter on which page a user lands first time. The div contains an UpdatePanel which has all the controls required for taking the details. This whole functionality is working fine.
The Problem: Now this div popup is not showing(by setting display:none) on subsequent postbacks(which I want), but the html markup is still loading with the page unnecessarily adding to the page size. What I would idealy want to do is: Check if flag cookie is set. If no, show the popup, else remove the popup's markup from the page.
Now since the div is not a server control, I cannot possibly remove it and the all the controls inside it. So, I thought of removing the UpdatePanel from the page:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["flag"] != null)
{
if (Page.Controls.Contains(updpnl_contact))
{
Page.Controls.Remove(updpnl_contact);
updpnl_contact.Dispose();
}
}
}
But I guess this tends to work with dynamically added controls only, and since the control is added at Design Time, it is not being removed.
Is there any way I can achieve this?
If you add a runat="server" attribute to your <div> element, it will be available in the code-behind. You'll need an id on it as well. Then you can just toggle the Visible property. If this property is false, the control won't be rendered to the client (i.e. no HTML markup).
What you're trying to do is not at all the usual workflow. I tend to think that it will not work as it would mess up control tree, maybe even corrupt the viewstate and so on.
As a possible solution, you can put it's visibility to hidden in the code behind. This, in the contrary to the usual 'gut feeling', doesn't work like the css propery 'display:none' for example - instead the control will not even be rendered into the page when it's not visible. This may be the workaround for you.
Happy coding.
A more efficient approach would be to create the panel as a UserControl and load it dynamically in codebehind when it's needed, then add it to your page. E.g, in code:
MyPopupControl popup = (MyPopupControl)Page.LoadControl("/path/to/usercontrol.ascx");
PopupPanel.Controls.Add(popup);
Where PopupPanel is an empty <asp:Panel>. Then, not even the markup will need to be loaded/processed except when its needed.
There is no reason that all the code you use to display and process this panel couldn't also be in the usercontrol, isolating it from the master page.
Can you build the panel dynamically, based on the cookie setting?