Solved

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

Posted on 2007-03-27
3
706 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

690 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