Solved

How do I pass arguments to an OnDataBinding function?

Posted on 2004-10-03
4
1,693 Views
Last Modified: 2012-08-13
I have a linkButton inside a repeater and I call a function OnDataBinding to add a client side confirm prompt to it. I would like to know how I can pass an argument into this function so I can pass in a string to use as the prompt.

Here is what my link button looks like currently...

<ASP:LinkButton ID="deleteLink" RunAt="Server" OnDataBinding='AddConfirmToLink' OnCommand="ProcessArticleCmd" CommandName="ProcessArticleCmd_delete" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"recordID") %>' Text="Delete" CausesValidation="False" />


Thanks :)

b
0
Comment
Question by:WillyCornbread
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 12214487
Add the prompt string to your command argument.

CommandArgument='<%# DataBinder.Eval(Container.DataItem,"recordID") & ":PromptHere" %>'

If you pass the CommandArgument into the function, you can do something like this:

Dim ca As String() = "recID:Prompt".Split(":".ToCharArray())
Dim sID As String = ca(0)
Dim sCA As String = ca(1)

The sID would have the record id and the sCA would have the command argument.

John
0
 

Author Comment

by:WillyCornbread
ID: 12217344
I was under the impression that the CommandArgument was only available to the OnCommand event handler and not to both the OnDataBinding and OnCommand. Can you please confirm that this is NOT the case and I will test your suggestion?


Thanks!

b
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 250 total points
ID: 12221365
My bad in the sense that I thought you were using the ItemDataBound event, which is what I would suggest you try:

If you want to configure the buttons that appear in repeater items, use the ItemDataBound event like this:  Let's say your button is named cmdPromptConfig.

If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
     ' resolve control.
     Dim btn As Button = CType(e.FindControl("cmdPromptConfig", Button)

     ' call your routine, passing the instance of the button, to configure it for the prompt.  you will have access
     ' to the CommandArgument which should have been set from your data binding code.
End If

John
0
 

Author Comment

by:WillyCornbread
ID: 12221548


Thanks, that will work :)

Much appreciated.

b
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question