473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Multiple variables in a commandargument

I'm trying to figure out this little piece of code so that I can send more then 1 value through the commandargument.

Converted this code from C but having a problem. probably something really stupid.

The Error I am getting is

Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

Line 138:
Line 139: Dim String1 = arg(0)
Line 140: Dim String2 = arg(1)
Line 141:


I first thought it might be a null or empty value, but I don't think that's the case


Here is the code

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
  4. <asp:LinkButton ID="LinkButtonWebsiteURL" runat="server" Text='<%# Container.DataItem("CompanyWebsiteName")%>' CommandName="WebsiteClick" OnCommand="Btn_WebClick" CommandArgument='<%#Eval("UserAccountsID") + ";" +Eval("CompanyWebsiteURL")%>'/>
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. Protected Sub Btn_WebClick(ByVal sender As Object, ByVal e As CommandEventArgs)
  12.  
  13.  
  14.         Dim commandArgs As LinkButton = CType(sender, LinkButton)
  15.         Dim info As String = commandArgs.CommandArgument
  16.         Dim arg() As String = New String(2) {}
  17.         Dim splitter() As Char = {";"c}
  18.         arg = info.Split(splitter)
  19.  
  20.         Dim String1 = arg(0)
  21.         Dim String2 = arg(1)
  22.  
  23.         Response.Write("Worked: " & String1 & " " & String2)
  24.  
  25.  End
  26.  
  27.  
  28.  
Dec 9 '10 #1
3 7156
Fixed!

working code

Expand|Select|Wrap|Line Numbers
  1. <asp:LinkButton ID="LinkButtonWebsiteURL" runat="server" Text='<%# Container.DataItem("CompanyWebsiteName")%>' CommandName="WebsiteClick" OnCommand="Btn_WebClick" CommandArgument='<%# Container.DataItem("UserAccountsID") + ";" + Container.DataItem("CompanyWebsiteURL") %>'/>
  2.  
  3.  
  4.  
  5.  Protected Sub Btn_WebClick(ByVal sender As Object, ByVal e As CommandEventArgs)
  6.  
  7.  
  8.         Dim commandArgs As LinkButton = CType(sender, LinkButton)
  9.         Dim info As String = commandArgs.CommandArgument
  10.         Dim arg(2) As String
  11.         Dim splitter() As Char = {";"c}
  12.         arg = info.Split(splitter)
  13.  
  14.  
  15.         Dim String1 = arg(0)
  16.         Dim String2 = arg(1)
  17.  
  18.  Response.Write("Worked: " & String1 & " " & String2)
  19.  
  20. End
  21.  
  22.  
Dec 9 '10 #2
Frinavale
9,735 Expert Mod 8TB
Just a suggestion, but you should probably check to see if the array has two items in it before accessing the items...

For example:
Expand|Select|Wrap|Line Numbers
  1. Protected Sub Btn_WebClick(ByVal sender As Object, ByVal e As CommandEventArgs)
  2.  
  3.  
  4.         Dim commandArgs As LinkButton = CType(sender, LinkButton)
  5.         Dim info As String = commandArgs.CommandArgument
  6.         Dim arg() As String = info.Split(";"c)
  7.  
  8.         If arg IsNot Nothing AndAlso arg.Length > 1
  9.           Dim String1 = arg(0)
  10.           Dim String2 = arg(1)
  11.           ErrorLabel.Text = "Worked: " & String1 & " " & String2
  12.         Else
  13.            ErrorLabel.Text = "Didn't work, the array was not the correct length."
  14.         End If
  15. End Sub
  16.  
Also, I do not recommend using Response.Write in your VB.NET code because it tends to place the string that you are writing into an invalid place in your HTML. I recommend using a Label, Literal, or a Localizable control to display the text instead of using Response.Write.

-Frinny
Dec 9 '10 #3
Thanks frinny

some good advice. will try it out
Dec 10 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: ben3003 | last post by:
I am trying to put a date in my database in the form dd-mm-yyy, as for my PHP page is returns 3 variables $date, $month, $year. is ther a way to put these together? i have tried imploding them but...
10
by: Johnny Lin | last post by:
Hi! Is there a way to automate the unbinding of multiple variables? Say I have a list of the names of all variables in the current scope via dir(). Is there a command using del or something...
2
by: KathyB | last post by:
Hi, figured out where I was going wrong in my post just prior, but is there ANY way I can assign several variables to then use them in an Update statement, for example (this does not work): ...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
1
by: syntego | last post by:
I am using DB2 V8 fixpack 10 and have the following issue: >From a User Defined Function, I can assign multiple variables in a single statement as follows: -- Get the first update transaction...
7
by: r.z. | last post by:
This is from Visual Studio docs. But is this standard behaviour? I mean, is it ok in every environment: class A { B* my_pointer; A(); ~A(); }
21
by: vlsidesign | last post by:
This syntax does not to work nl, nt, ns = 0; The only one that get's initialized is ns. nl and nt because they don't initialize seem to get some junk from memory. I have done these two...
7
mrnn
by: mrnn | last post by:
Ok I know how to save and load 1 variable from a file, but when it comes to loading multiple variables, I get confused. And all the articles I've found using Google and on here haven't helped too...
3
by: pwilliams | last post by:
For example: info= input('Enter name address and telephone number\n') I have tried declaring variables in advance ie. var1 = " " var2 = " " var3 = " " but to no avail. Can you please help ?...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.