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

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}" />

Related

MSAccess VBA: Pass values from a subform to a seperate form

I have a form frmDetail that contains several locked fields I want populated only when another form has been filled out, in the name of having some kind of standardization in my data. This other form frmSignOut is used to enter in a date and location that will populate the fields on frmDetail. frmSignOut also contains a subform subULookup that looks up users from a different table using an identifier number. The resulting last name, first name and phone # should also be passed to frmDetail. I also hope to combine first and last name somehow into a Last,First format.
My approach so far has been to open frmSignOut modally with acDialog and I inserted Visible=False into the On_Click event on frmSignOut. Then I try to reference my subform fields and set them to the desired fields on frmDetail. I finish by refreshing and then closing the dialog form.
Private Sub CmdSignOut_Click()
DoCmd.OpenForm("frmSignOut"),,,,,acDialog
If CurrentProject.AllForms("frmSignOut").isLoaded=True Then
Set Forms!frmSignOut!SubULookup.PhoneNbrTxt=Me.ContactNbrTxt
DoCmd.Close (acForm), ("frmSignOut")
Me.Refresh
End If
End Sub
I have only been able to get this far, trying to pull the first field PhoneNbrTxt. I can get frmSignOut to open, I put in data and when I click my 'close' command button I get run-time error 438: Object doesn't support this property or method.
The line highlighted is where I try to reference my subform field. I also have a 'Cancel' button added to frmSignOut that just closes the form, I have no errors there.
Again I'm completely new to Access without much prior experience in anything related, I'd appreciate any knowledge you guys can throw at me.
EDIT: I've been able to successfully pull the value to Me.ContactNbrTxt by adjusting my code to the below.
Me.ContactNbrTxt = Forms!FrmSignOut!SubULookup.Form!PhoneNbrTxt
It looks like the missing part was the Form! right before the control name, along with formatting this correctly and dropping Set.
Im still trying to work out how to combine first and last name before also pulling those to frmDetail, if anyone can help there.

SqlDataSource ControlParameter not working

I have a dropdown (selProject) populated by a SQL table. The value is the id field, the name is the name field.
I have a gridview control fed by a sqldatasource.
What I want to do is to conditional where clause based on the selProject dropdown. I have spent 3 hours searching and trying to figure this out. I fear I am going to snap and kill a co-woker.
When I choose a specific value in the dropdown, the selectedValue of the control is "40". I verified this through debugging. This is correct and expected.
I have a controlParameter that looks like:
<asp:ControlParameter ControlID="selProject" PropertyName="SelectedValue" Name="ProjectIDPass" Type="Int32" />
The SelectCommand includes: (Batches.ProjectID = #ProjectIDPass) as part of the Where clause.
I get no rows, no errors, no problems. The issue I suspect is that the SelectedValue of the dropdown is a string and the Batches.ProjectID is an integer.
When I hard code 40 into the where clause in place of #ProjectIDPass, it works great. When I go back to the ControlParameter is bombs out. I have tried all manner of conversion techniques.
Is there any way to see the SqlDataSouce SelectCommand that was executed with actual values in place of the parameters.
The issue I suspect is that the SelectedValue of the dropdown is a string and the Batches.ProjectID is an integer.
Doubtful - the Type property handles the conversion, and your RDBMS would as well (though it'd probably convert the int column to string, screwing your indexes).
Is there any way to see the SqlDataSouce SelectCommand that was executed with actual values in place of the parameters.
A RDBMS profiler like Sql Profiler would be the best way. But you can also hook the SqlDataSource.Selecting and SqlDataSource.Selected events and examine e.Command and e.Arguments.
So I solved my issue, and it was a complete lack of understanding how GridViews are handled.
I wanted to load data based on values from 2 Drop Downs without doing a post back. This way, a user can go from page to page and not have to keep setting dropdowns. That isn't possible till the page is loaded, as the dropdowns are not set until the page load is nearly complete. Gridviews are populated on Page Init. I could use the cookies I was setting to set the data in SQL query, but if the user changes a drop down, the cookies are not reset with the new data until the page loaded, so I would be loading the wrong data.
I found a solution, which is to allow the page to load, then use the values of the boxes which are set properly at that point, and use them to query a dataset and asign it to the GridView. The trick to get it to actually display the data since the page is fully loaded at this point, is an update panel.
See this article for full description: http://www.aspsnippets.com/Articles/Bind-Load-GridView-after-Page-load-is-completed-using-AJAX-UpdatePanel-in-ASPNet.aspx

How to get dynamic created table's total column and row using Request.Form in vb.net

I am doing my project in Vb.net using MVC 4.0
I have created dynamic table and in that textboxes in td using javascript and now i want to get that table's total row and column as well for further process in Controller function.
How I can get using above using VB.net?
I have used Request.Form but the id of the textboxes in table is created uniquely so first I want to find the total column and row so based on that I can move further and check using for loop.
It seems like if you are generating your table through javascript you should also be able to set the value of a hidden field to the value you are outputting to your totals column. If you created a hidden field with the value set you should be able to access it from the Request collection. If it is not actually in a field that gets posted back you will only be able to access the value from the client-side.
document.getElementById("myInput").value = "Value you are outputting to your "total" cell
[Solved]
I got all the controls on code behind by it's name by using FormCollection just i need to do is post back the form using form action method because with using ajax i am not getting the formcollection in code behind but directly using form action method i can get all the controls name.
These are the textbox ids by which i can get the value just need to do further process like:
For Each _formvalues As String In formcol
formcol(_formvalues)
Next
fomcol is an object of FormCollection,_formvalues is used for moving one by one name coming in formcol and to take the data inside means name just write formcol(_formvalues) that's it.

How to generate adidional fields inside Yii form

I have:
Table "user"
id, username, password
Table "freedate"
id, user_id, start_date, end_date
Each user can have 1 or more (unlimited) number of "freedate" entries.
Now i have form with 2 text fields (username and password), and 2 date pickers (one for start date and another one for end date).
How can i enable user to inserd aditional datepicker pairs so they can enter as much of "freedate" entires as they need to?
I was wondering about insertind aditional button inside form, that would somehow create aditional fields when pressed, but u have no idea how to do it.
I don't need working example (even tho one would help ofc). What i need i suggestion from your own expirience if you had similar problem.
You can use javascript as noted above. Though that can get tricky to get the new fields associated with the datepicker.
You can also submit after each pair is entered. On returning back to form after save insert a new set of start/end date fields to the end of the form. This way they always have a freedate pair they can enter. (a bit slower overall)
You need javascript to generate these fields on the fly. Or a fixed amount of extra fields could be hidden and shown one by one using javascript as the user clicks the button. You would need to keep track of the number of fields being shown in a javascript var.
You need to write custom javascript in order to do that. It isn't hard, you would need to do something along these lines:
You need to create a button and, when that button gets clicked (onClick event or jquery click() function) you can add the html for your field (<input type=.... /> and so on to your form) and remember to use the correct name for these fields so that they get sent correctly when the user submits the form.

Generate dynamic web pages and urls in 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"]