How to use webbrowser control to turn the div visibility into visible? - c#

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?

Related

Navigating from div tags within the same page using buttons?

I am developing a website using asp.net/C#
I want to create a button that can save user data then move to a div tag at the same page.
I already did the saving part, but how do I make the same button to navigate to a different div tag within the same page?
some people use the response.redirect method to navigate to a different page. I want to navigate to a div tag within the same page. For example:
Experience
after I press that it will take me to:
<div class="panel" id="experience">
I want to do the same but with button that can do both that and saving to a DB. As I said, I already did the saving part.
I tried this:
<asp:Button ID="Button1" runat="server" Text="Save & Continue" OnClientClick="#experience" OnClick="Button1_Click" />
But it didn't work.
any ideas? I am trying to access that div tag from code behind
If this is WebForms and you don't want to use javascript, then, after you do the save, you can do a Response.Redirect to the same url, but with the anchor tag, e.g. Response.Redirect("myPage.aspx#experience").
This really depends on the rest of your code though. I suggest posting the relevant parts of your code behind so that we can better see what you have done. Also, don't try to avoid javascript - it is too useful to avoid.
ASP.NET has a Focus method that can be applied to the following ASP.NET server controls:
Button
LinkButton
ImageButton
CheckBox
DropDownList
FileUpload
HyperLink
ListBox
RadioButton
TextBox
At the end of your Button1_Click event handler code-behind, add something along this lines of this:
TextBoxExperience.Focus();
Note - The TextBox control with ID of TextBoxExperience control would be inside of the experience DIV.

Popup windows to select items on ASP.NET

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.

Displaying a content page as popup in asp.net,using

I have a content page(Say.. invoice.aspx) in asp.net application with master pages.
The content page(invoice.aspx) is using a gridview, which displays records from database.
Currently i am navigating to this page using - Response.redirect("invoice.aspx") and this is working fine.
But i need to display this page as pop-up from calling page, so that this popup invoice can be seen on the top of other pages.
Please help me if this can be done using javascript or some other way.
Thanks in advance..
A page popup can be implemented using a div as a container with a different style (opacity, window position, size etc) and has a higher z-index than the rest of the page.
thus basically you need a structure like
<div class="overlayOuter">
<div class="overlayInner">
<!-- external content to be loaded here -->
</div>
</div>
and now using AJAX you load the invoice.aspx page to the inner container and show the container and reduce the opacity of the outer container.
There should be libraries out there that let you do this. you need to explore that on your own.
You can use modal popups for the above scenario:
one example can be found here: http://sandbox.scriptiny.com/tinybox2/
its easy and not much code you need to write and also can load popup as an iframe so postbacks can be handled without posting back parent page or you can use ajax
function OpenWindow(strChildPageUrl) {
var testwindow = window.open(strChildPageUrl, "Child", "width=700px,height=650px,top=0,left=0,scrollbars=1");
testwindow.moveTo(100, 0);
}
</script>

How to add style to a image when you hover over it, in asp.net website

I have a image in my website, How can I add style to it so that it looks like a real button. now when I click it or move the mouse over it there is no changes to the image. when click or the mouse it over it how can I add style to it. Thanks
<asp:ImageButton ID="Img_ComposeMessage" PostBackUrl="~/SendMessage.aspx" ImageUrl="Styles/Images/ComposeMessage.png"
runat="server" />
Sounds like something you can easily accomplish with JavaScript / jQuery; just hook into the mouseover event and change the image then.
If you're worried about flash of unstyled content, you could switch to using css background/spriting for your image along with an asp:linkbutton instead of an asp:imagebutton
Here's a quick tutorial to get you started - http://www.learningjquery.com/2007/02/quick-tip-set-hover-class-for-anything
You have to use Javascript and/or CSS styling to change the ImageButtons properties.
Client Side javascript method calls can be added to the ImageButton's OnClientClick Property.
To ensure you have a static ID property on the control when rendered, for use with CSS effect or JQuery, use the ClientIDMode Property, set it to Static, the ID property you define with be rendered.

jquery context menu and asp update panel

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 :)

Categories