Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a text box, list box and two button. When I click button1 the webaddress entered is moved to listbox. Like that by adding more than one webaddress to list box.Now when I click second button the address in list box open in multiple new window. My code is:

XML
<table>
    <tr>
    <td>
    <asp:TextBox ID="txtMail" runat="server"></asp:TextBox>
    </td>
    <td>
    <asp:ListBox id="List" runat="server" ></asp:ListBox>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:Button ID="btnClick" Text="Click" runat="server"/>
    </td>
</table>


In code behind
protected void Button1_Click(object sender, EventArgs e)
{
   List.Items.Add(txtMail.Text);
}

protected void btnClick_Click(object sender, EventArgs e)
{
  //what can i do here
}


by using javascript means tell me the code
Posted
Updated 10-May-11 0:11am
v4
Comments
Tarakeshwar Reddy 22-Apr-11 12:23pm    
Cleaned up pre tags
Abdul Rahman Hamidy 3-May-11 7:32am    
is there a problem if you add items to listbox using javascript and you then loop using javascript and open new window foreach item of the listbox.
beginner in C#.net 3-May-11 7:39am    
i m not familiar with javascript... suggest me how to do...

You want to use Response.Reidrect and specify the target frame/window. I googled "asp.net response target", and this was one of the more than 4.6 MILLION results returned:

C#
public static class ResponseHelper 
{
    public static void Redirect(this HttpResponse response, string url, string target, string windowFeatures)      
    {
        if ((String.IsNullOrEmpty(target) || target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))          
        {  
            response.Redirect(url);
        }
        else
        {
            Page page = (Page)HttpContext.Current.Handler;
            if (page == null)
            {
                throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
            }
            url = page.ResolveClientUrl(url);
            string script;
            if (!String.IsNullOrEmpty(windowFeatures))
            {
                script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
            }
            else
            {
                script = @"window.open(""{0}"", ""{1}"");";
            }
            script = String.Format(script, url, target, windowFeatures);
            ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
        }      
    } 
} 


With this you get nice override on the actual Response object

C#
Response.Redirect(redirectURL, "_blank", "menubar=0,scrollbars=1,width=780,height=900,top=10"); 


Google reveals all.
 
Share this answer
 
v2
Hi,
u can take url present in list box in javascript.

code as follows
HTML :

<select id="ssPayMode"  önchange="ViewiNewWindow(this.value);"  runat="server">
                                        <option value="www.google.com">your url</option>
                                        <option value="www.yahoo.com">your url</option>
                                    </select>


Javascript:
function ViewiNewWindow(val)
{
   var url = val;
   window.open(url ,'mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')
}



this method is called on listbox change. same way u can do on click.
 
Share this answer
 
v2
Comments
beginner in C#.net 3-May-11 10:02am    
my 5..
i didnt find what i expect.. but i learn another method
tnx...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900