Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2007-03-27
3
702 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

791 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