using dropdownlist without postback for filling textboxes - asp.net

Hello i got a drop down list with post back from worker data base .
I also got a grid view with that data base.
when i choose a worker on the drop down i got 5 text boxes that are being filled from the right row on the grid view.
My question is how can i do that without using the auto post back?
p.s I am using visual studio with vb.net
Thanks in advance!
atm i am using something like this but i am really trying to remove all not needed postbacks from my site.
Protected Sub workerDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles workerDropDownList.SelectedIndexChanged
Dim x As Integer
For x = 0 To workerDataGrid.Rows.Count - 1
If workerDataGrid.Rows.Item(x).Cells(1).Text = workerDropDownList.SelectedValue Then
editWorkerNameBox.Text = workerDataGrid.Rows.Item(x).Cells(0).Text
editWorkerIdBox.Text = workerDataGrid.Rows.Item(x).Cells(1).Text
editPhoneBox.Text = workerDataGrid.Rows.Item(x).Cells(2).Text
editCellPhoneBox.Text = workerDataGrid.Rows.Item(x).Cells(3).Text
editEmailBox.Text = workerDataGrid.Rows.Item(x).Cells(4).Text
editUserNameBox.Text = workerDataGrid.Rows.Item(x).Cells(5).Text
editUserPassBox.Text = workerDataGrid.Rows.Item(x).Cells(6).Text
editIsManagerBox.Text = workerDataGrid.Rows.Item(x).Cells(8).Text
editIsActiveBox.Text = workerDataGrid.Rows.Item(x).Cells(7).Text
End If
Next
End Sub

Related

find dynamic added panel

i'm adding a panel like this to my web application:
For i = 1 To amountOfRechnungspositionen + 1
Dim pnlPositon As Panel = New Panel
pnlPositon.ID = "pnlPositon" & i
pnlRechungsposition.Controls.Add(pnlPositon)
...
Next
Now if i onclick a button, i want to delete this panel.
This is my code.
Private Sub imgDelRechnungsPosition_Click(sender As Object, e As ImageClickEventArgs) Handles imgDelRechnungsPosition.Click
amountOfRechnungspositionen = Convert.ToInt32(hfAmountofRechnungspositionen.Value)
Dim fcpnlPositon As Panel = DirectCast(pnlRechungsposition.FindControl("placeholderID$pnlPositon" + amountOfRechnungspositionen.ToString()), Panel)
fcpnlPositon.Dispose()
hfAmountofRechnungspositionen.Value = Convert.ToString(amountOfRechnungspositionen - 1)
End Sub
But fcpnlPositon is Nothing.
Waht i'm doing wrong?
Thank u, for reading.
Try using:
CType(pnlRechungsposition.FindControl("pnlPositon" +
amountOfRechnungspositionen.ToString()), Panel)
The placeholder text is only for client-side markup and thus you want to use the direct ID property.

VB ASP.NET - Add code to a control that is created by code behind

I'm using VB ASP.NET and would like to know how to add code to a control that is created by code behind?
For example in my Main.aspx.vb file I have the following code:
Connection.Open()
spRetrieveAlbums.ExecuteNonQuery()
ReturnValue = spRetrieveAlbums.Parameters("#ReturnValue").Value
Connection.Close()
For I = 1 To ReturnValue
Dim myAlbum = New ImageButton
myAlbum.Visible = True
myAlbum.Width = 150
myAlbum.Height = 150
myAlbum.BorderStyle = BorderStyle.Solid
myAlbum.BorderColor = Drawing.Color.WhiteSmoke
myAlbum.BorderWidth = 1
AlbumsPanel.Controls.Add(myAlbum)
Next I
ReturnValue stores the number of albums a person has (Using SQL Server stored procedure ##ROWCOUNT) and displays the same amount of ImageButtons within the 'AlbumsPanel' Panel on the web page.
I would like to use response.redirect("Albums.aspx") on a click event on any of the ImageButtons but not sure how I can achieve this. Any suggestions?
you have created dynamically and you can use a delegate for min.VB10 and like that,
AddHandler myAlbum.Click, _
Sub(sender As Object, e As EventArgs)
//To Do for Response
End Sub

Access other asp:Controls from asp:ObjectDataSource-SelectMethod

I have a simple webcontrol.ascx with an listview and 2 Integer fields (show nbr. of certain elements). The Listview gets filled from an asp:ObjectDataSource.
My Problem is that both the listview and my 2 integer values need access to the same database table and I really dont want to make that call twice (Inside the Page_Load for the 2 fields and inside the SelectMethod for the ObjectDataSource)
The Problem is that I dont see a simple way for the two methods (Page_Load and SelectMethod) to exchange any data (with local properties for example).
private mydata As List(of ...)
protected Sub Page_Load(...) Handles Me.Load
mydata = DbManager.HeavyCall(...)
literalValueA.Text = (From i in mydata ..... ).Count
literalValueB.Text = (From i in mydata ..Where ... ).Count
End Sub
' SelectMethod for asp:ObjectDataSource
public Function GetData( ... ) As List(of ...)
mydata.DoSomething(...) ' mydata is Nothing here...
end Function
I hope someone can tell me a good solution (preferable without external cache..) of how to exchange data between the two methods..
The sad solution is: dont use the asp:ObjectDataSource...
Now Im using the asp:LinqDataSource wich provides a 'selecting'-event from where I can modify the Controls on my frontend.
' Selecting-Event from my LinqDataSource
private Sub myLinqDataSource_Selecting(sender .., e .. ) Handles myLinq..Selecting
dim mydata = DbManager.HeavyCall(..)
literalValueA.Text = (From i in mydata ..... ).Count ' works
literalValueB.Text = (From i in mydata ..Where ... ).Count ' works
e.Result = mydata
End Sub

VB.Net exception: Object reference not set to an instance of an object

I'm currently working on coding a web page for a school project. This site is supposed to be a simple online store where people can order prints of artwork. The specific page I'm working on has a Drop Down List (ddlArt) that is bound to my database and displays a list of the different art pieces available. When the user selects one of the items, all the information on that item is pulled from the database and displayed on the page in a variety of labels and such. The only thing is that I'm getting a null reference exception error saying "Object reference not set to an instance of an object" when I go to try to run the page. I got the same error on a homework assignment earlier in the year and managed to get it fixed, but I can't remember what I did and I can't get help from school until next week, so I thought I'd try my luck on here. Here's my code:
Private selectedArt As Art
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ddlArt.DataBind()
End If
selectedArt = Me.GetSelectedArt
lblArtID.Text = selectedArt.ArtID()
lblArtName.Text = selectedArt.ArtName()
lblCaption.Text = selectedArt.Caption()
lblDescription.Text = selectedArt.Description()
imgArt.ImageUrl = "~/images/" & selectedArt.FileName()
End Sub
Private Function GetSelectedArt() As Art
Dim artTable As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
artTable.RowFilter = "ArtID = '" & ddlArt.SelectedValue & "'"
Dim artRow As DataRowView = artTable(0)
Me.imgArt.ImageUrl = "~/images/" & artRow("FileName")
Dim art As New Art
art.ArtID = artRow("ArtID").ToString
art.ArtName = artRow("ArtName").ToString
art.Caption = artRow("Caption").ToString
art.Description = artRow("LongDescription").ToString
art.FileName = artRow("FileName").ToString
Return art
End Function
And here's the code for the Art class, in case anybody is interested:
Public Class Art
Public Property ArtID As Integer
Public Property ArtName As String
Public Property ArtType As String
Public Property Caption As String
Public Property FileName As String
Public Property Description As String
End Class
When I get the error, it highlights the artTable.RowFilter = "ArtID = '" & ddlArt.SelectedValue & "'" line in the GetSelectedArt function. I've tried comparing it to my corrected homework assignment that I mentioned, but I can't seem to find the problem. My VB is a little fuzzy because it's been awhile since I actually took the class. Any suggestions? Thanks a bunch!
If I understand your comment above correctly, on the initial page load there is nothing in the ddlArt, because the user must first choose an art type.
If that is correct, then your answer to my question is your answer.
For whatever reason (and without seeing at least the Select statement), artTbl is not getting instantiated, which is why you're seeing the Object reference not set to an instance of an object error.
One way to fix this (without knowledge of your SqlDataSource it's hard to give a precise answer) is to modify your Page Load method so that GetSelectedArt is only called when the user has selected an item from the drop down list. Right now GetSelectedArt is called every time the page loads.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ddlArt.DataBind()
Else
selectedArt = Me.GetSelectedArt
lblArtID.Text = selectedArt.ArtID()
lblArtName.Text = selectedArt.ArtName()
lblCaption.Text = selectedArt.Caption()
lblDescription.Text = selectedArt.Description()
imgArt.ImageUrl = "~/images/" & selectedArt.FileName()
End If
End Sub
However, the above modification will only prevent GetSelectedArt from being called on the initial page load. If your SqlDataSource.Select command is still returning nothing, then you're still going to have this problem.
A better solution would be to call the GetSelectedArt on the ddlArt.SelectedIndexChanged event handler. This way you'll know that you have (or should have) a valid SelectedValue from ddlArt.
Also, if you don't populate the drop down until the user selects an art type from the radio button list, why are you binding the drop down list on the initial page load (and what are you binding it to)? Or is the drop down list and detail information on a different page from the radio button list?
May be .. with ArtID as integer
artTable.RowFilter = "ArtID = " & format(ddlArt.SelectedValue)

menu with hierarchical data

I have a Hierarchical Table for Categories in this form NodeID ParentID NodeName
Following is the code i am using generate ASP.NET MENU ITEMS and bind it to MENU CONTROL
Private Sub displayMenu()
Using con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("HagglerEntLibConStr").ConnectionString)
Using sql As New SqlCommand("Select NodeID,ParentID,NodeName FROM Nodes", con)
con.Open()
Dim r As SqlDataReader = sql.ExecuteReader 'stored procedure that returns the above SqlDataReader
Dim tempMaster As New MenuItem()
Dim bagMaster(700) As MenuItem
Dim j As Integer = 0
Do While r.Read()
tempMaster.Value = r("NodeID").ToString()
tempMaster.ToolTip = r("ParentID").ToString()
tempMaster.Text = r("NodeName").ToString()
tempMaster.NavigateUrl = ""
bagMaster(j) = tempMaster
j += 1
tempMaster = New MenuItem()
Loop
r.Close()
Menu1.Items.Clear()
For i As Integer = 0 To j - 1
If i = 0 Then
Menu1.Items.Add(bagMaster(i))
Else
For x As Integer = 0 To j - 1
If bagMaster(i).ToolTip = bagMaster(x).Value Then
Dim c As MenuItem = bagMaster(x)
'you can change the tool tip here if you want
c.ChildItems.Add(bagMaster(i))
End If
Next x
End If
Next i
'Menu1.Items.RemoveAt(0)
End Using
End Using
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
displayMenu()
End Sub
Everything works fine ...but the main disadvantage with this approach is that the Menu CONTROL creates HTML TABLES...i have around 1000 rows in the table..this creates a multi level menu ...which adds a lot of HTML Tables in the page and increases the page load time drastically...how do i tackle this issue?? This is the way the menu populates.
Have you tried with the RenderingMode property?
Values:
Default. (This is the default value). The rendering mode depends on the RenderingCompatibility control property, if this setting is set to 3.5, the default rendering is a table, if this value is 4.0, the default rendering mode is a list ul. You can change this setting globally in the web.config file:
<system.web>
<pages controlRenderingCompatibilityVersion="4.0"/>
</system.web>
Table. Renders as a table
List. Renders as a list
Update 1
Since you are using the .Net Framework 3.5, probably the best way to accomplish this is to use Control Adapters
Basically the adapters work on a specific control, and in the adapter you can update the rendering of the target control, in this case the Menu control
I have not created a control adapter, so I cannot give you further information other than pointing you in the right direction, googling I found this article which seems promising:
http://msdn.microsoft.com/en-us/magazine/cc163543.aspx

Resources