简体   繁体   中英

Open a webpage when first click on a TextBox

I need open a webpage when first click on a TextBox in form c# ASP.NET 4 .

I think for resolve this problem use the OnTextChanged property in TextBox :

<asp:TextBox ID="tb1" runat="server" CssClass="24" OnTextChanged="tb1_TextChanged"></asp:TextBox>

And in code-behind I have added:

protected void tb1_TextChanged(object sender, EventArgs e)
{
    Response.Redirect("http://www.google.com/");
}

But the redirect not working.

How to resolve this?

OnTextChanged is a server side event . It would be better to use JavaScript for this purpose like this:

<script type="text/javascript" language="javascript">
    function Open() {
        window.showModalDialog("http://www.google.com/");
    }
</script> 

And to open webpage when onclick :

<asp:TextBox ID="TextBox1" runat="server" onclick="Open();"></asp:TextBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM