Generate dynamic web pages and urls in vb.net - vb.net

New to the whole web programming scene, usually stick to offline applications.
On this page of my site I'm using gridview to pull items from an SQL database.
That's all fine and dandy, but here's where I get confused.
Upon selection of an item I want to navigate to another page which is generated with information from my SQL database, I'm fine here, I have a template for the page that pulls information for the page based on the selected item using a get property for a WHERE itemname= sql command.
However, currently, the site goes like this. http://exampleurl.com/items.aspx
I would like users to be able to link to a specific item. So upon selection it should generate a url for that item.
http://exampleurl.com/items.aspx?=selecteditemname

Never mind.
I'm just being a tard as usual.
Set the column in your gridview to a hyperlink
navigateurl='<%# String.Format("../Default.aspx?id={0}", Eval("ColumnId"))%>'
Open up the code for the page you are redirecting to and set your WHERE in the gridview to
Request.RawUrl.Split("=")(1)
This will get everything after the '=' in your url.
i.e.
http://exampleurl.com/Default.aspx?id=123
Request.RawUrl.Split("=")(1) will return '123'
OR
Dim item As String = Request.Url.Query
Dim query As NameValueCollection = HttpUtility.ParseQueryString(item)
Dim id As String = query["id"]

Related

WebBrowser.DocumentText Not Updating

I am loading a web page into webbrowser control and after waiting for the document to load, I am reading in the .documenttext to retrieve various bits of data.
I then want to test if the data on the web page has changed (it's a dynamic update) and if so, I retrieve the updated data.
The problem is that .document.text is not updating, either after a dynamic update to the page or if I physically navigate within the browser control to another page.
When I loop through all elements using '.getelementsbytagname' I get the up to date web page data, but obviously want to avoid this if the data hasn't changed. So '.document' updates but '.documenttext' doesn't.
So the '.documenttext' doesn't get updated when the web page changes. Is there a way to force this update? Or a better/simpler way to check for a page update?
.refresh() does work, but I don't want to be reloading the document when it's already up to date.
Dim pp = Uni.wbUni.DocumentText
If pp = GlobalVariables.unistr Then
Console.WriteLine("no change" & Now())
Exit Sub
End If
Console.WriteLine("change" & Now())
GlobalVariables.unistr = Uni.wbUni.DocumentText
So from the above pp never actually updates
Dim pp = Uni.wbUni.Document.Body.InnerText

How can I redirect to the same page multiple times with a different query string?

I have a page that contains a table with a list of data and an icon (on each row) which redirects the user to a new aspx page with a queryString and does some custom logic to then download the file. The user has asked that we make a "download all" button so they don't have to go through and manually click every icon in every row.
My code is close, I feel, but it will hang after the first file is downloaded and will never progress further.
Here is the code I have so far
Protected Sub ibDownloadAll_Click(sender As Object, e As ImageClickEventArgs)
'Get Parameters
'Run stored procedure to get the query string we're going to use
'Fill DataSet
For Each myItem As DataRow In ds.Tables(0).Rows
Response.Redirect("redirectPage?ID=" &myItem.Item("ID")) 'Gets stuck after here
Next
End Sub
I realized if I added the second parameter (Indicates whether execution of the
current page should terminate)
Response.Redirect("redirectPage?ID=" &myItem.Item("ID"), False)
Then it would make it to the end of the function, running through the loop as expected, but then only outputting/downloading the last file.
Is there something I'm missing or an alternative that can be used to effectively redirect multiple times? Unfortunately with the framework I'm using I'm not able to use Response.Write and put custom scripts in that way, nor can I really change the page that we are redirecting to.
You can't redirect to multiple pages (a redirect close the request) and you also can't send multiple files. Your only option would be to have a request that zip all the files together. You can do this with System.IO.Compression.ZipArchive. You don't need to save the zip on disk, you could just send the memory stream.

Visual Basic Web Browser change form when certain webpage content detected

I am trying to make a form on VB.NET that when a certain webpage is loaded into the web browser (in this case its a .txt file with a string of numbers). It will look for those numbers and if it finds them it will close that form and open another. I have tried to do it many times and my latest attempts came out with this code. Any help would be appreciated.
Dim passcontents As String
passcontents = WebBrowser.DocumentText = "test.com/test.txt"
If WebBrowser.DocumentText = "test.com/test.txt" And passcontents Then
ActualGen.Show()
Me.Close()
Else
End If
There are a couple of basic problems with the code you've posted.
1) Are you trying to test passcontents as a boolean or a string? You've defined it as a String, but then you are trying to assign the equality of two other strings to it, as you would a Boolean.
Try setting Option Strict On at the top of your code - it gives a few more helpful pointers to check in this case.
2) The If... Then condition is checking the same data as passcontents (may) already be providing. Are you just trying to check that the correct page is loaded, or do you want to check for certain page contents as well?
You appear to be getting mixed up between the browser's document URL and the loaded document contents.

Syntax for SharePoint 2010 BCS URL Action to populate New form

Have seen several posts with solutions for native SharePoint lists, including the very useful SPUtility.js (only for native SharePoint lists). But nothing to pass a value from a BCS list to a new BCS list. The Query string filter will not connect on the New form (no web part to connect it to) and does me no good on the lists page (already have that working).
A "go write custom code for everything" is not a solution for me.
There should be a way to 1) pass the value in the URL (ideal - what's the syntax?) or 2) make some other simple change, perhaps to the select list for the item -- I just can't find it. Have seen quite a few posts with similar questions. The Microsoft documentation is not useful and there are more questions on the "social" topics than answers.
Here's what I have:
I have a BCS list (sends item) tied to a BCS related list (receives item).
I have an action on the related list (ECT) to create a new item. Works fine with no parameters. I get a blank new form. The new form allows me to enter two items and choose two items (exactly as intended).
What I would like to have is the necessary ?something=something string so that my user does not have to select one of the choice items (MNumber - set as a key / required value)
User selects "New" from Actions.
Form Opens
MNumber is automatically filled in based on the MNumber of the current item displayed in the BCS related list.
The string I supply is accepted. Does nothing.
/intake/Lists/ContactsList/NewForm.aspx
/intake/Lists/ContactsList/NewForm.aspx?MNumber=1234
The string I supply is rejected - cannot be saved or insufficient values.
/intake/Lists/ContactsList/NewForm.aspx?MHICNumber={$MHICNumber}
Have also tried passing a string to one of the text fields (instead of the select field). Can't get that to work either. I've spent quite a few hours with the various boards. Nothing helpful.
Would also be nicer if I could set the New form to display in a pop-over window (as it does when I select New from the list view). Opening a new browser window is hokey and replacing the existing one is a navigation pain for the user.
Have this working ... Thanks to Kit Menke!
Created an Action on the External Content Type in the BCS....
/intake/Lists/ContactsList/NewForm.aspx?IDnumber={0}&Source=/intake/scheduling.aspx
where
parameter property 0 is the IDNumber from the ECT
The NewForm.aspx was edited to add a hidden content editor web part with references to three scripts Kit wrote - two supporting and one that sets the values.
http://site/list/NewForm.aspx?toolpaneview=2
User selects the Action on the displayed ECT list
Action uses the URL to go to the New page with the data
Kit's script adds the data to the form and puts in the date and time.
Note: The ID field needs to be a text field. Cannot be a selection list.

hyperlink in asp.net that takes the value to the next page

im using asp.net with vb.net in backcode. On my first page, i diplay names of all employees. I want to give that a hyperlink, that when clicked upon shall open the next page with say a querystring and opn only that employees records. Also I want the save the employeeid (which is not shown on page 1) on the second page, cause when i do updates on second page, I want to use that employeeId in "where" clause for update or insert statements.
any ideas?
If you're not concerned about people messing the with query string you can use that and then just get the data out in the next page during the Page_Init or Page_Load using:
HttpContext.Current.Request.Item("EmployeeID")
However, I'm a fan of not using the query string because people tamper with it. You can use the PostBackUrl property of your hyperlink (if you use the asp linkbutton), and in the next page you can use the Page.PreviousPage object to access any objects from the previous page.
<asp:LinkButton ID="lnkEmployeeLink23232" runat="server" CommandArgument="23232" PostBackUrl="NextPage.aspx" Text="Employee Name" />
You'll have to check for IsCrossPagePostBack on the first page to make sure you don't fire databinding unnecessarily, but at that point you should be able to get to the control that fired the postback and from there get the command argument which would be the employee id in question.4
http://msdn.microsoft.com/en-us/library/ms178139.aspx
http://www.developerfusion.com/code/4687/cross-page-postbacks-in-aspnet-20/
If you are using a datagrid or gridview, you can use the hyperlink field:
<asp:hyperlinkfield headertext="Employee Page"
datatextfield="Employee"
datanavigateurlfield="EmployeeID"
datanavigateurlformatstring="Employee.aspx?employeeid={0}" />