I creat one WEB project, this project contain tow WEB FORM, In the first Web Form Design i have tow TextBox for Entring the date(All dataTable between this tow dates) and one Button, I want that when i press to to this Button it will load the second WEB FORM and show all the Data Table in DataGrid In this WEB FORM, So i need To call this tow TextBox value from the first WEB FORM to the second WEB FORM In Load_Page i will use this tow value in select statment. So i want to know how to call this to value from the first WEB FORM. I'am using VB.NET WEB APPLICATION.i have allrady DB in SQL .
you have a lot of ways to pass values from page to another like query string, sessions, etc....
Another way to achieve this is by using the PostBackUrl property of the button.
Refer Button..::.PostBackUrl Property for more information
You can use querystring to get last page values to load page. Use this code
Response.Redirect("Default.aspx?value1 =" & value & "&value2" & value)
write page name as like default.aspx.
In the button click on the first page, you can call the second page by using Server.Transfer like this:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
TextBox1.Text = TextBox1.Text & " Add something before continue..."
Server.Transfer("SecondPage.aspx")
End Sub
Then you can get the textbox from the first page in the second page Page_load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim lastPage As Page = Context.Handler
Dim textBox As TextBox = lastPage.FindControl("TextBox1")
End Sub
If you don't need to do anything on the button event other than posting to the next page, you can do it simpler...
Definition of the button in the ASPX markup for the first page:
<asp:Button id="Button1" PostBackUrl="SecondPage.aspx" Text="Continue" runat="Server"/>
Then you can get the textbox from the first page in the second page Page_load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim textBox As TextBox = PreviousPage.FindControl("TextBox1")
End Sub
Related
Wasn't able to find anything about this situation:
I have two RadDatePicker inside RadGrid for start and end date change
<telerik:RadDatePicker ID="rdpStartDate" Skin="Library" EnableEmbeddedSkins="false" CommandName="StartDateChange" runat="server" />
By itself, they work fine, but now I have a situation when I need to call method when their value has been changed (CommandName was added for this)
I know how to do this outside RadGrid, basically:
Protected Sub rdpStartDateChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) Handles rdpStartDate.SelectedDateChanged
...
...
End Sub
But I wasn't able to do this inside RadGrid, because nothings seems to trigger it.
I tried to catch my command with this (works for buttons at least):
Protected Sub rgLibraryItemCommand(ByVal sender As Object, ByVal e As GridCommandEventArgs) Handles rgLibrary.ItemCommand
But, no, it doesn't see CommandName="StartDateChange"
What I need to do to be able to catch those Date change events if RadDatePicker
is placed inside RadGrid?
You need to identify the control inside the grid which triggers the action. I'm not sure which is the way for Rad to do that but it should be similar this:
Private Sub DataGridView1_ButtonClick(sender As DataGridView, e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellButtonClick
'TODO - Button Clicked - Execute Code Here
End Sub
So you need to find the events for the DataGridViewRow for Rad and substitute them with the ones cell clicking events. This example should get you started.
Subscribing to an event on a control inside a RadGrid does not work the same way, because there could be multiple copies of the control or even none at all, depending on how many records are in the Data Source. Therefore, in order to subscribe to events on these controls, you have to do it manually after the data is bound, either in the ItemCreated event or ItemDataBound event.
Protected Sub rgLibraryItemCreated(ByVal sender as Object, ByVal e As GridItemEventArgs) Handles rgLibrary.ItemCreated
If TypeOf e.Item Is GridDataItem Then
Dim item As GridDataItem = e.Item
Dim rdpStartDate As RadDatePicker = item.FindControl("rdpStartDate")
AddHandler rdpStartDate.SelectedDateChanged, AddressOf rdpStartDateChanged
End If
End Sub
We have an aspx page built using Telerik controls, on a dropdown selected index change event at the server side, we are assigning a value to a textbox, but when the page is viewed the textbox value is not shown.
Code used:
Protected Sub Dropdown_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.WebControls.RadComboBoxSelectedIndexChangedEventArgs) Handles dropdown.SelectedIndexChanged
txtCost.Text = finalcost.ToString()
Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "OpenModelPopup();", True)
End Sub
I have a page with GridView. The GridView has select button. Normally I use GridView's selected index changed event to do all kinds of operations when user clicks select button. But now I want to do some operations in Page_Load event based on grid view's selected row. Since the Selected_Index_changed event occurs after Page_Load how do I know following things in page load event.
I checked the asp lifecycle and this other question but I dont know how to do this.
How about using a QueryString to transmit which row was selected and then in the Page_Load event get the QueryString parameters? This is an example.
Protected Sub LinkButton1_Command(sender As Object, e As CommandEventArgs)
Dim UserId As Integer = e.CommandArgument 'Here goes whatever value you're trying to pass
Response.Redirect("~/OtherPage.aspx?UserId=" _
& UserId)
End Sub
This is in the OtherPage.aspx
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
UserId = Request.QueryString("UserId")
'Your code
end sub
We have an ASP.Net / VB.Net code-behind web form. On this form is a GridView and a DetailsView.
When there is a change in the details view we would like the changes to be reflected in the GridView.
This code is being used to populate the GridView:
Private Sub Teachers_Init(sender As Object, e As EventArgs) Handles Me.Init
' Load the data from the database into the GridView.
'---------------------------------------------------
GridViewSummary.DataSource = theTableAdapter.GetDataAllTeachers
GridViewSummary.DataBind()
End Sub
This coding is being used to reflect the changes in the GridView after a change to the details are made in the DetailsView:
Private Sub DetailsView_ItemUpdated(sender As Object, e As DetailsViewUpdatedEventArgs) Handles DetailsView.ItemUpdated
' Refresh the data so current values are displayed.
'--------------------------------------------------
GridViewSummary.DataSource = theTableAdapter.GetDataAllTeachers
GridViewSummary.DataBind()
End Sub
Is there a way to not need the use of:
GridViewSummary.DataSource = theTableAdapter.GetDataAllTeachers
in the above coding? I know it's just 1 line of code but would like to eliminate it if it's not needed.
I have two aspx pages the first page has a textbox and the second aspx page has one textbox
In the second Page I am giving value to the text box by generating a session and giving that session ID to the textbox on the samepage
Now I need to retrieve back that session ID from the textbox and display it in first aspx page textbox which is not happening and not getting any error.
Here is my code for the first aspx page:
<asp:TextBox ID="CopySession" runat="server"></asp:TextBox>
This is my code for displaying the retrieved Session ID:
If IsPostBack Then
Dim text1 As TextBox = Me.PreviousPage.FindControl("SessionValue")
CopySession.Text = text1.Text
End If
This is my second aspx page:
<asp:TextBox ID="SessionValue" runat="server"></asp:TextBox>
This is my code behind for second aspx page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("ID") Is Nothing Then
Session("ID") = Guid.NewGuid.ToString
SessionValue.Text = Session("ID")
End If
End Sub
Its quite simple just type cast it with previous page like following
(Me.PreviousPage as yourPageClass).SessionValue.Text
or use this on first page
<%# PreviousPageType VirtualPath="~/SecondPage.aspx" %>
and better way is
internal function TextBoxText() as string
return SessionValue.Text
end function
and get it on page one
currentPageTextbox.Text = Page.PrevousPage.TextBoxText
If you put it Session, just retrieve it. On Page_Load of your first page, do:
Dim sessionID As String = TryCast(Session("ID"), String)
If Not String.IsNullOrEmpty(sessionID) Then
SessionValue.Text = sessionID
End If
Am also looking around the same scenario and I found this URL as useful to me.
Am sharing this to you.. Exploring Session in ASP.Net
Refer this too
How can I access Session vars from Base class in ASP.Net?
ASP.Net MVC: How do you access the session from a different project within the solution?