Open a Web Page according to Textbox Value

Posted by Johnbhatt under ASP.NET AJAX category on | Points: 40 | Views : 1679
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.


<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 = "";
case 'acer':
window.location = "";

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..

Comments or Responses

Login to post response