How to split string in asp.net web application - asp.net

I want to split string using textchanged event.
example i have 10000853,154SSDAAS but i just want to retrieve only 10000583.
I try to use split but it doesn't work. Can someone help me.
Here is my code:
Private Sub AssetTxt_TextChanged(sender As Object, e As EventArgs) Handles AssetTxt.TextChanged
Try
Dim split() As String = AssetTxt.Text.Split(",")
If split.Count > 2 Then
AssetTxt.Text = split(0)
End If
Catch ex As Exception
End Try

This is what you're looking for, you've disabled the split for two items:
If split.Count > 1 Then
Your original code would work for values like 10000853,154SSDAAS,123456

Related

using dropdownlist without postback for filling textboxes

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

Get product inventory list from Magento API v2 using asp.net

Just figured out how to get a sessionid back using http://xxx.xxx.xxx/api/v2_soap?wsdl and nothing seems to work. The code below returns the following:
Line that has error:
prodListRequest = ws.catalogProductList(sessionId, filter, "")
Error returned:
Value of type '1-dimensional array of CompanyADevMagento.catalogProductEntity' cannot be converted to 'MagentoService.catalogProductReturnEntity'.
Does anyone have a asp.net vb example of getting inventory list?
Thanks.
Imports CompanyADevMagento
Imports System.Xml
Partial Class site_magento
Inherits System.Web.UI.Page
Dim sessionId As String = ""
Protected Sub btnShowData_Click(sender As Object, e As System.EventArgs) Handles btnShowData.Click
Dim ws As New CompanyAMagento.MagentoService
Dim sOutput As String = ""
sessionId = ws.login("username", "yourapipassword")
litOutput.Text = "Session: " & sessionId
Try
Dim filter As New filters
Dim prodListRequest As New MagentoService.catalogProductReturnEntity
prodListRequest = ws.catalogProductList(sessionId, filter, "")
Catch ex As Exception
litError.Text = ex.ToString
End Try
End Sub
End Class
-Magento Version using: 1.7.0.2
-Currently set Magento Core API > WS-I Compliance = Yes
I'm not too familiar with ASP, however it looks to me that your code is expecting the wrong object type.
The catalogProductList API method returns an instance of catalogProductEntity, while your code seems to expect catalogProductReturnEntity.
The latter is returned from the catalogProductInfo method.
CatalogProductEntity
CatalogProductReturnEntity
From the docs: http://devdocs.magento.com/guides/m1x/api/soap/catalog/catalogProduct/catalog_product.list.html

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)

Online Test using ASP.NET / Linq

Working on a Online Test.
I have 3 tables
Questions
Subject
Topic
I have made a stored procedure which returns 25 random records. I want to store it in-memory and then display 1 question at a time with AJAX. I don't want to hit database 25 times as there are many users, I tried and store the result in viewstate but then I am not able to cast it back. if I use
Dim qus = from viewstate("questions")
it works, but it doesn't work when I retrieve 1 record at a time.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
ViewState.Add("QuestionNo", 0)
Dim qus = From q In PML.PM_SelectRandomQuestionFM Select q
viewstate.add("questions",qus)
LoadQuestion(0)
End If
End Sub
Private Sub LoadQuestion(ByVal i As Integer)
Dim QuestionNo As Integer = CType(ViewState("QuestionNo"), Integer) + 1
Try
If QuestionNo <= 25 Then
Dim qus = viewstate("questions")
Me._subjectTopic.Text = String.Format("<b>Subject:</b> {0} -- <b>Topic:</b> {1}", qus(i).subjectName, qus(i).TopicName)
Me._question.Text = " " & qus(i).Question
Me._answer1.Text = " " & qus(i).Answer1
Me._answer2.Text = " " & qus(i).Answer2
Me._answer3.Text = " " & qus(i).Answer3
Me._answer4.Text = " " & qus(i).Answer4
Me._questionNo.Text = String.Format("Question No. {0} / 25", QuestionNo)
ViewState.Add("QuestionNo", QuestionNo)
Else
Server.Transfer("freeMemberResult.aspx")
End If
Catch ex As Exception
Throw New System.Exception(ex.ToString)
End Try
End Sub
I tried casting the object to
Dim qus = CType(ViewState("questions"), IQueryable(Of PM_SelectRandomQuestionFMResult))
but then I get this error
System.Linq.Enumerable+WhereSelectEnumerableIterator`2
Please HELP or if there is any other method to do it, if my method of doing online test is wrong.
Regards
IMO, you're over-engineering this. Why screw around trying to hold the data in memory? Why not write each question to a div, and then hide all of the question divs except for the "current question".
Much easier to implement and you're not hitting the server with several AJAX calls, This also make saving state (previously answered questions, etc) much, much easier.
Have you tried just using Session to maintain state? Is there a requirement that prohibits you from doing this?
Dim qus = CType(Me.Session("questions"), IQueryable(Of PM_SelectRandomQuestionFMResult))

Resources