 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 16th, 2007, 03:34 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You know what happens .If i have a list of say
abc
bad
bcd
aad
And i type bcd the bcd is highlighted in the list but when i pree enter the list scrolls upto the first item and no postback happnes.Also if i try to do mouse click,still the same-no postback happnens..
I dont understand.
I am implementing IPostBackDataHandler .I referred to this MSDN article
http://msdn.microsoft.com/library/de...singsample.asp
But still the same.
Thanks
Kamal
|
|

February 16th, 2007, 04:08 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Ok, this control works fine. I see what your saying, the problem is the code that you used here:
if(keyCode==13)
_doPostBack(clientid,' ')
Which should of actually thrown you an error.
If should of been:
if(keyCode ==13)
{
__doPostBack('clientid','')
}
Notice its 2 underscores, not one.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
|
|

February 16th, 2007, 04:19 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am sorry,i should have told you the exact code.I actually have two underscores .If you notice in the whole Java script that i sent you.
sb.Append(" __doPostBack('" + clientID + "','');");
I guess this is alright.
|
|

February 16th, 2007, 04:35 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have another script that works with type ahead but again if i hot enter the selection goes to first item and nothing happens.
string sReturn= "<SCRIPT>";
sReturn += "var txtval = '';";
sReturn += "var curlist;";
sReturn += "function select(trigger){ ";
sReturn += "curlist=trigger;";
sReturn += "for (n=0;n<curlist.length;n++){";
sReturn += "if(curlist[n].text.toLowerCase().indexOf(txtval.toLowerCase())= =0){";
sReturn += "curlist.selectedIndex=n;break;";
sReturn += " }else{";
sReturn += " if (n==curlist.length-1) txtval=''; curlist.selectedIndex=0;}}}";
sReturn += "function dodefaultaction(e){ ";
sReturn += "var code; ";
sReturn += "if (!e) var e = window.event; ";
sReturn += "if (e.keyCode) code = e.keyCode; ";
sReturn += "else if (e.which) code = e.which;";
//sReturn += "if(code == '9' | code == '40' | code == '38') return ''; ";
sReturn+="if(code=='13') alert('enter hit!');";
sReturn += "else return code;}";
sReturn += "function change(trigger){ ";
sReturn += "var code = dodefaultaction(); ";
sReturn += "if(code == ''){ txtval='';return false;} ";
sReturn+="else if(code=='13'){";
sReturn+="txtval = txtval + String.fromCharCode(code)";
sReturn+="__doPostBack('"+this.ClientID+"','');}";
sReturn += "else{";
sReturn += "if(code == '8'){ txtval='';} ";
sReturn += "else{";
sReturn += "txtval = txtval + String.fromCharCode(code);}select(trigger); return true;}}</SCRIPT>";
return sReturn;
|
|

February 16th, 2007, 04:39 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
if(code == 13) //return /enter key
{
if (document.getElementById(âdrpâ) != null) {
__doPostBack(âdrpâ,â)
return false;
}
^^ that works
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
|
|

February 16th, 2007, 04:55 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using a custom control and document doesnt work in there.Do you want me to try just the script in the aspx form?
|
|

February 16th, 2007, 05:13 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the link.I am going through it.But one thing that came to my mind is that did you ntoice how i put alert in the java script on keycode==13 .Interesting part is ideally when i hit enter this alert should pop up but that doesnt happen.So this means its not going to that line of code.
And also if i do the script straight in the code in HTMl using <script> it still works the same.So i think its the script and not the code.
If scipt works,code works too.
Thanks
Kamal
|
|

February 16th, 2007, 05:43 PM
|
|
Authorized User
|
|
Join Date: Dec 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I read the whole article and figured that i am doing something like this.Here is code of my custom control.
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
namespace DropDownWebControl
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:SmartDropDown runat=server></{0}:SmartDropDown>")]
public class SmartDropDown : System.Web.UI.WebControls.DropDownList,IPostBackDa taHandler, IPostBackEventHandler
{
private string text;
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
private Boolean isLoaded = false;
public object EventServerChange;
public event EventHandler SelectedIndexChanged;
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected virtual void OnSelectedIndexChanged(EventArgs e)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged(this,e);
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
Page.GetPostBackEventReference(this, "OnSelectedIndexChanged");
output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
output.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
output.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
output.RenderBeginTag(HtmlTextWriterTag.Input);
output.RenderEndTag();
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Page.RegisterClientScriptBlock("SmartDropDownScrip t", GetScriptBlock());
}
protected void RenderBaseControl(System.Web.UI.HtmlTextWriter output)
{
base.Attributes["onKeypress"] = "return (dodefaultaction()==''); ";
base.Attributes["onKeydown"] = "return (dodefaultaction()==''); ";
base.Attributes["onKeyup"] = "return (change(" + base.ClientID + "));";
base.Attributes["onfocus"] = "txtval = '';";
base.Attributes["onblur"] = "txtval = '';";
base.Render(output);
}
protected virtual void RenderAttributes(HtmlTextWriter writer)
{
if (base.ID != null)
{
writer.WriteAttribute("id", base.ClientID);
writer.WriteAttribute("name", this.UniqueID);
}
if (!this.Enabled)
writer.WriteAttribute("Enabled","false");
writer.WriteAttribute("ParentFormID", this.ClientID);
if (this.AutoPostBack)
{
string sOnChangeCmd = this.Attributes["onchange"];
if (sOnChangeCmd != null)
{
this.Attributes["onchange"] = (sOnChangeCmd.EndsWith(";")) ? sOnChangeCmd + Page.GetPostBackEventReference(this, String.Empty)+ ";" : sOnChangeCmd + ";" + Page.GetPostBackEventReference(this, String.Empty);
}
else
{
this.Attributes.Add("onchange", Page.GetPostBackEventReference(this, String.Empty));
}
}
this.Attributes.Render(writer);
}
protected void RenderHiddenInput(System.Web.UI.HtmlTextWriter output)
{
output.Write("<input type='hidden' value='' name='hidden" + base.ClientID + "'>");
}
protected string GetScriptBlock()
{
string sReturn= "<SCRIPT>";
sReturn += "var txtval = '';";
sReturn += "var curlist;";
sReturn += "function select(trigger){ ";
sReturn += "curlist=trigger;";
sReturn += "for (n=0;n<curlist.length;n++){";
sReturn += "if(curlist[n].text.toLowerCase().indexOf(txtval.toLowerCase())= =0){";
sReturn += "curlist.selectedIndex=n;break;";
sReturn += " }else{";
sReturn += " if (n==curlist.length-1) txtval=''; curlist.selectedIndex=0;}}}";
sReturn += "function dodefaultaction(e){ ";
sReturn += "var code; ";
sReturn += "if (!e) var e = window.event; ";
sReturn += "if (e.keyCode) code = e.keyCode; ";
sReturn += "else if (e.which) code = e.which;";
//sReturn += "if(code == '9' | code == '40' | code == '38') return ''; ";
sReturn+="if(code=='13') alert('enter hit!');";
sReturn += "else return code;}";
sReturn += "function change(trigger){ ";
sReturn += "var code = dodefaultaction(); ";
sReturn += "if(code == ''){ txtval='';return false;} ";
sReturn+="else if(code=='13'){";
sReturn+="__doPostBack('"+this.ClientID+"','');}";
sReturn += "else{";
sReturn += "if(code == '8'){ alert ('backspace');txtval='';} ";
sReturn += "else{";
sReturn += "txtval = txtval + String.fromCharCode(code);}select(trigger); return true;}}</SCRIPT>";
return sReturn;
}
public void RaisePostBackEvent(String eventArgument)
{
if (eventArgument == null)
{
return;
}
}
public virtual void RaisePostDataChangedEvent()
{
this.OnSelectedIndexChanged(EventArgs.Empty);
}
public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string sValue = Text;
string sPostedValue = postCollection[postDataKey];
if (!sPostedValue.Equals(sValue))
{
Text = sPostedValue;
return true;
}
return false;
}
}
}
|
|

February 16th, 2007, 05:45 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Did you get it working?
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
|
|
 |