CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2007
    Posts
    238

    need help in opening a popup window

    HI Again,
    I have another query which could be simple but i am not able to resolve it. I need to have a button or link in my page which needs to open a popup window and need to be able to send a variable attached to the link which comes from a database.

    the url goes like this
    Code:
    
    'list.aspx?id="+Databinder.Eval(Container.DataItem, "Id")'
    The code is in a <asp:Repeater>. I can have a <asp:button> control and call a c# function onclick event like this
    Code:
    void popup(object sender, System.EventArgs e){
    buttonid.Attributes.Add("onclick","window.showModaldialog('url','','height:px, width:px') etc
    }
    1. how do i access the id from the database in this code
    2. how do i attach a variable to the url
    3. is there a better way to do this, like link or anyother instead, but there is no onclick event in the hyperlink tag so i can't say 'window.open there? Any other suggestion?

    THanks

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: need help in opening a popup window

    Code:
           //page load of list.aspx with querystring id=..
           protected void Page_Load(object sender, EventArgs e) {
              string url = "navigateUrl.aspx?id=" + Request.Querystring["id"]; //or get the id somewhere else from
               
              string popup = string.Format("window.showModaldialog('{0}','','height:px, width:px');", url);
    
              button1.Attributes.Add("onclick", popup);
           }

  3. #3
    Join Date
    Mar 2007
    Posts
    238

    Re: need help in opening a popup window

    THanks for the reply.
    THe id is coming for the database not from previous page.

    Code:
    <asp:repeater id="myview">
    <....
    >
    <tr>
    //so i add a hyperlink I can pick up the value from the database using 
    <td><asp:hyperlink navigateurl='<%# "nextpage.aspx?folder="+DataBinder.Eval(Container.DataItem, "ID")%>' ........
    
    
    
    
    </td>
    </tr>
    ....
    </asp:Repeater>
    this opens a new full IE window, i want a popup. If i try as a button and doesn't seem to get it right.

    Code:
    <asp:repeater id="myview">
    <....
    >
    <tr>
    //so i add a hyperlink I can pick up the value from the database using 
    <td><asp:button onclick='window.open(<%# "nextpage.aspx?folder="+DataBinder.Eval(Container.DataItem, "ID")%>', height,width)  ........
    
    
    
    </td>
    </tr>
    ....
    </asp:Repeater>
    or try like this
    Code:
    /or
    <td><asp:button onclick="popup">
    
    //c# code in the same aspx page
    void popup(object sender, System.EventArgs e){
    
    
    //how do i get the value from the database here, there is no value attribute to a button
    //which i call to differentiate different button that are clicked and where do i add the attribute.
    
    Btn.Attributes.Add("onclick", "window.showModalDialog('target.aspx','', 'dialogHeight: 200px; dialogWidth: 300px;')");
    
    }
    Hope i make sense now.

  4. #4
    Join Date
    Mar 2007
    Posts
    238

    Re: need help in opening a popup window

    I tried everything and anything but the only way i could make it work is

    Code:
    <input type="button" onclick="javascript:window.open('target.aspx?id=<%#DataBinder.Eval(Container.DataItem,"id") %>','','height=350,width=350');"   value="-">
    even the <a href> doesn't work if i add the onclick code, and leaves the href="#", it tries to open a new window and then opens the popup.

    <asp> tags i always get the server tag is not well formed, infact if i try to include runat="server" in the above code, i get the same error message.

    I am not sure if it's a good idea to mix <asp:> tags and standard html tags, i need to test this in several system to make sure it works.

    Any suggestion is welcome.

  5. #5
    Join Date
    Jan 2009
    Location
    Cochin, India
    Posts
    40

    Smile Re: need help in opening a popup window

    If you are really keen to stick with asp.net server controls you could have an anchor inside your repeater and add the href attribute through code in the item data bound procedure. You will have to include a hidden field in your repeater though.

    If your repeater is something like

    Code:
            <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
            <ItemTemplate>
                <asp:HiddenField ID="myh" value='<%#DataBinder.Eval(Container.DataItem,"id") %>' runat="server" />
                <a id="mya" runat="server" />
            </ItemTemplate>
            </asp:Repeater>
    then the Repeater1_ItemDataBound procedure would be

    Code:
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HiddenField h = (HiddenField)e.Item.FindControl("myh");
                HtmlAnchor a = (HtmlAnchor)e.Item.FindControl("mya");
                a.HRef = "javascript:window.open('target.aspx?id=" + h.Value +  "','','height=350,width=350')";
                a.InnerText = h.Value;
            }
        }
    This would open a pop up with target.aspx when you click on the link.

    Warm Regards,
    Jay
    Support Resort
    http://www.supportresort.com
    Bringing offshore expertise to the world

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured