?
Solved

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

Posted on 2007-03-27
3
Medium Priority
?
709 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 1500 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

Independent Software Vendors: 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

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

800 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