What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 33851 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET AJAX > Open a Web Page according to Textbox Value ...
Johnbhatt

Open a Web Page according to Textbox Value

 Code Snippet posted by: Johnbhatt | Posted on: 6/22/2012 | Category: ASP.NET AJAX Codes | Views: 731 | Status: [Member] | Points: 40 | Alert Moderator   


Hi,
We will learn how to Open a Web Page based on Textbox Value.
In this tutorial, we are using: Visual Studio 2010, XHTML 4.01, JavaScript, ASP.NET Ajax, C#

We put a Textbox Control in Empty Web Form. Inserted a Script Manager in Page and Used an AutocompleteExtender to Textbox. Then We wrote a method for AutoCompletion List which ,I used Static, you can change according to your need. Then created a Simple JavaScript Function and Applied to Textbox. Lets make clear through Code.

ASPX Code (XHTML):

<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:TextBox ID="txtNewDate" runat="server" onblur="Redirect()"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtNewDate_AutoCompleteExtender" runat="server" DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionList" ServicePath="" TargetControlID="txtNewDate" UseContextKey="True" MinimumPrefixLength="1"> </asp:AutoCompleteExtender>


Now JavaScript Code which is Inserted Directly in Head Section. (JavaScript)
<script language="javascript" type="text/javascript">

function Redirect() {
var day = document.getElementById("<%=txtNewDate.ClientID%>").value;
switch (day) {
case 'hp':
window.location = "http://www.hp.com/";
break;
case 'acer':
window.location = "http://www.acer.com/";
break;
}
}
</script>


Now Code in Back End ASPX.CS (C#)
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] Brands = { "hp", "acer", "dell", "lenovo" };
return (from m in Brands where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}

Now Try this at your Machine....
Best of Luck..

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 4:56:49 AM