Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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