I'm currently trying to spider a page that seems to have a dynamic form. First let me explain the form. The form has 3 radio dials above the search bar that has the first dial selected upon loading. I need the second dial selected. After selecting the second dial from the 3 dials I need to fill out the search bar which is actually a drop down,
in the inspector looks like
" id="*****" class="ui-autocomplete-input" type="text" size="60" name="*****" style="font-size:20px;width:90%;;" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">>"
Originally the html behind the search/submit button looks like
a id="submit_button" style="display:none;" href="#">
After selecting from the dropdown menu the html behind the search/submit button looks something like
a id="submit_button" style="" href="report.php?**=Mzg4MDU4NQ%3D%3D&**=MjQ1NDM2NQ%3D%3D">
Obviously the stars are there to keep the page anonymous. I'm using a Web client to spider this page.
All I need to grab from this page is the new href link which is dynamically changed after a item is selected from the drop down. I need to simulate this in C# and parse the href link. Frankly, I don't know where to even begin.
I have tried using a nameValueCollection to fill in this form using UploadValuesAsync() but no avail.
Related
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.
Background
Here's what I want to happen:
A user is on one page1.html (jsFiddle).
When they click on one of the <a href...> links, I want to navigate to page2.html (jsFiddle) and simulate the user entering the number into the textbox and clicking on the button.
Example: On page1.html, user clicks on display 2. Then we will navigate to page2.html and get an alert of 2 (as if user had entered 2 and clicked the button).
Question
How do I do this?
Is there a way to make a C# method with a specific URL to navigate to, such as page2.html/searchfor/2?
Or is there some way in JavaScript to manually go about doing other things after navigating to <a href="page2.html">?
Things I've tried
Using a <span> with an onclick function, but then it's not a true link like <a href> where I can middle click to open in new tab and right click to follow link
Wrapping my first attempt in <a href> tags, like <span>Display 2</span>. This still doesn't solve the problem of performing extra actions after navigation.
Note
I am building this webpage using Entity Framework, ASP.NET MVC, and C#.
I have simplified the problem for discussion purposes, but the concept is the same.
Try using the page2.html document's onload() function. You can pass parameters through the URL, then take that data and perform "other actions" as soon as the document is loaded.
I have an ASP.NET project (non-MVC) and I'm also using Bootstrap 3.0. This is my first time using this combination and need some guidance.
I have a gridview with a buttonfield column. Right now everything is showing up just fine with my gird and Bootstrap table formatting and its binding to my datatable - no problems there.
Next, I want to make the click of the button in the Buttonfield column to initiate a modal window and display a modal based on a unique ID from the row button that opened it.
I don't really know how to tie this all together with ASP.NET and Bootstrap. HTML literals? Dynamic ASP.NET panels? It doesn't matter to me whether there is a postback or not, I'd really just like some guidance or even pseudo-code on how these can be tied together.
Since the OP specifically requested bootstrap help...
You should go through the bootstrap documentation for modals http://getbootstrap.com/javascript/#modals
It makes no difference if you are using MVC or not and you should not need to do any kind of post back to display the modal.
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" />
Will trigger element with id myModal to be shown.
Using bootstrap's own demo code in this jsfiddle demonstrates opening and dismissing the modal.
For the second part of the question, this updated jsfiddle shows how you can also use the button click event to set a value in the modal. You could do other actions in that event handler like get or send data to the backend or change other elements in the modal.
For your case, you would want to handle all button clicks in a single event handler but you can store the id in a custom attribute on the button element. I like to use custom attributes instead of parsing from name, id, or class attributes. This is the bootstrap convention.
$(function() {
$('button.btn').on('click', function() {
var value = $(this).attr('data-value')
$('div.modal').find('#target').text(value);
});
});
Here I have broken out how to get the custom attribute value from the button instance which was clicked.
Post what you have so far and what you still can't get working.
This also shouldn't be tagged with C# or asp.net as that is irrelevant.
You might need a simple js function to take care of that(as mike mentioned this has nothing to do with using or not using bootstrap since it is just some css stuff):
var RunDialog;
$(document).ready(function () {
RunDialog = $("#Id").dialog();
});
You can use ASP.Net Ajax ModalPopup for ASP.Net Web Form. You can google a lot of examples regarding GridView with ModelPopup.
ModalPopupExtender inside a GridView ItemTemplate
I want to make the click of the button in the Buttonfield column to
initiate a modal window and display a modal based on a unique ID from
the row button that opened it.
ModalPopup should work with Bootstrap.
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 am trying to auto submit form using webbrowser control. I am using the following code to submit"
currentElement.InvokeMember("submit");
Now this methods works fine. But sometimes a form may have some javascript function that is called on button click at the time of submission. So let's say if a form has some button image called "Submit" and when a user presses it, a javascript function somefunction() is called and then form is submitted.
Problem is when I use the above method InvokeMember then it only submits the form and doesn't execute associated scripts (in this case somefunction()) and I have to manually write code
webBrowser1.Document.InvokeScript("somefunction");
But this requires that I know before hand if there is some function. Is there any way I submit form and it will automatically run all associated javascript?
And I don't know button name or ID either which is clicked by user to submit form. Because in some cases it may not even have ID or name for e.g.
<span class="btn" onclick="somefunction()">
<img style="cursor:pointer" title="Submit" alt="Submit" src="http://stackoverflow.com/imagesbutton.png?2012">
<div id="s" style=""></div>
</span>
It's been a while since I have messed around with the WebBrowser control, but I used to make it jump through hoops for me. I've come across this issue in the past.
http://www.codeproject.com/Tips/60924/Using-WebBrowser-Document-InvokeScript-to-mess-aro
When you get a Form object, take the string out of the OnSubmit and run this to execute it before submitting the form:
object[] codeString = {"myObject.setVariable(0);"};
webBrowser1.Document.InvokeScript("eval",codeString);
Works like a charm.
If you know the name or id of the image tag you can use
webBrowser1.Document.GetElementById("button").InvokeMember("click");
or
webBrowser1.Document.GetElementByName("button").InvokeMember("click");
to call the associate function in javascript