开发者

how to use image button to open the url in another window

Hi I know how to acheive this in hyperlink by setting target = _blank , how can i开发者_JAVA百科 do this using image button control , below is my code:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" />

             <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
            ControlToValidate="txtPostcode1" ErrorMessage="Postcode is required"  ValidationGroup="group2"></asp:RequiredFieldValidator>
            <br />

Code behind:

    protected void test_Click(object sender, ImageClickEventArgs e)
{

    Response.Redirect(String.Format("http://maps.google.co.uk/maps?saddr={0}&daddr=&daddr=Wigan+WN6+0HS,+United+Kingdom&iwloc=1&dq=Tangent+Design", txtPostcode1.Text));



}

Any help or advice will be highly appreciated


protected void Page_Load() {
   ControlID.Attributes.Add("target", "_blank");    
}

If that doesn't work, try adding this to your ImageButton:

<asp:ImageButton runat="server" OnClientClick="window.open('http://url/to/open');" ></asp:ImageButton>


I just figure it out..

On Page_Load event, put

    this.Form.Target = "_blank"; // Will set all link's target to a new window

Then for example in a image button Click event, you put:

    Response.Redirect("http://stackoverflow.com");

It will simply open this page in a new tab. Try it :)


you could use the Attributes collection to add "target","_blank"

this should add the target attribute to the anchor link surrounding the image


Add target="_blank" to onClientClick will do the trick


In the code behind.

imgbtn.OnClientClick = "target='blank'";

And you're done.


Try this:

<asp:ImageButton OnClick="test_Click" ImageUrl="/images/contactUs/directionbtn.png" ID="test" runat="server" ValidationGroup="group2" OnClientClick="form1.target ='_blank';" />


this.Form.Target = "_blank"; 

This way the client can see what he wants in a new page, since the server and what is available and his account in the site available at the beginning PageLoad

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜