Solved

Dynamic image button passing argument from datagrid (vb.net)

Posted on 2007-03-27
3
697 Views
Last Modified: 2008-02-01
VB.Net Web Form application question.

I am trying to create an image that acts as a link and when clicked calls another page as a popup, passing along one parameter. I assume that imagebutton is what I need to use to accomplish this.

I'm stumped though.

I will have to put this into place in two different areas (and two different mechanisms):

First, what I assume is the easiest area:
- a simple page that accepts new entries or updates of one record -- no datagrid involved -- and if you are in 'update' mode (not insert mode), the button should appear. The button will need to pass the key from the calling screen to the popup page.

Second is more complicated:
a datagrid that's fully editable -- and i need to pass the contents of one of the DATABOUND columns on the selected row to call the popup page.

How do I accomplish this? My obstacles that I'm encountering are -- do I have to have the command event triggered by clicking the image button call a javascript routine, or is there something I can do directly? The popup page is a databound .aspx page that accepts one argument passed in, does a query and displays readonly list of data based on the argument (key) passed in.

Offering 500 points for a quick complete solution. Thanks.
0
Comment
Question by:nonesuch
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
igor_alpha earned 500 total points
ID: 18804271
Hi nonesuch,
You can accomplish this by using  RegisterStartupScript method.

On ImageButton click EventHandler you would register startup script which will open popup page with some query string variables. Variables will be passed based on required controls values.
For example, for first case it would be TextBox1.Text value:

 string popupScript = "<script language='javascript'>" +
  "window.open('default.aspx?id='"+TextBox1.Text+", 'CustomPopUp', " +
  "'width=200, height=200, menubar=yes, resizable=no')" +
  "</script>";

Page.RegisterStartupScript("PopupScript", popupScript);

For datagrid solution will be same. If contents of datagrid bound column is text you can use following syntax:
MyDataGrid.SelectedItem.Cells[1].Text
0
 
LVL 3

Author Comment

by:nonesuch
ID: 18807982
Okay, that worked for the first case.

But I don't understand how I can do the same for a datagrid solution -- I have 15 rows showing from my datagrid, do I register 15 startup scripts, one at a time when I click on the various image buttons in that datagrid?

Can you actually write out what I would have for the imagebutton within a datagrid and its event handler?

This is what I did for the first case:

    Private Sub imgView_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgView.Click
        Dim strScript As New StringBuilder
        strScript.Append("<script language='javascript'>window.open('popuphistory.aspx?id=")
        strScript.Append(id)
        strScript.Append("','History','width=500,height=200,menubar=no,resizable=yes')")
        strScript.Append("</script>")

        Page.RegisterStartupScript("PopUpHistory", strScript.ToString)

    End Sub
0
 
LVL 3

Author Comment

by:nonesuch
ID: 18808299
Never mind... I figured out an alternative way to do the datagrid anyway.

<asp:Label ID="lblHistory" Runat="server">
<a onclick='window.open("popupHistory.aspx?id=<%# Container.DataItem("ID") %>","popup","width=550,height=300,scrollbars=1,resizable=1,menubar=0");'
href="javascript:void;"><img src="images/lookup.gif" alt="View History" border="0"></a></asp:Label>

Thanks for your push in the right direction.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now