sbornstein2
asked on
Need Help with Textbox event firing off. Urgent
Hello all. I need some help. I have an enter key javascript event that will fire off the code I need. I need this to fire off on a textbox. Well I have one big problem. The code in the ASPX is creating this textbox I need to fire off and I the onkeypress would fire. I am trying to work around having to do a rebuild of the whole site code and just an ASPX change. Here is the javascript:
<script language="javascript">
function enterSubmits(eventObj, obj)
{
alert('here ye');
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==10 || keyCode == 13) // CR/LF
{
__doPostBack('L_SR_search' ,'');
}
return true;
}
</script>
This would work perfect on an onkeypress but this is what I have a stupid control like so:
<customer:usercontrol id="L_SR_searchType" CssClass="box" runat="Server" />
the HTML code generates like so if I look at the source
<input name="L_SR_searchType:text Value" type="text" value="1004434" id="L_SR_searchType_textVa lue" class="box" />
Is there a way to handle this somehow without changing the code behind. For example, if I use a regular textbox and then place an onkeypress it works fine, its this damn control giving me the problem. Here is an example of what does work fine but I have to use this control because its referenced in the code behind for things.
<asp:textbox id="L_SR_TEST" cssClass="box" onKeyPress="javascript:ret urn enterSubmits(event, this)"
runat="server"></asp:textb ox>
Thanks all
<script language="javascript">
function enterSubmits(eventObj, obj)
{
alert('here ye');
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==10 || keyCode == 13) // CR/LF
{
__doPostBack('L_SR_search'
}
return true;
}
</script>
This would work perfect on an onkeypress but this is what I have a stupid control like so:
<customer:usercontrol id="L_SR_searchType" CssClass="box" runat="Server" />
the HTML code generates like so if I look at the source
<input name="L_SR_searchType:text
Is there a way to handle this somehow without changing the code behind. For example, if I use a regular textbox and then place an onkeypress it works fine, its this damn control giving me the problem. Here is an example of what does work fine but I have to use this control because its referenced in the code behind for things.
<asp:textbox id="L_SR_TEST" cssClass="box" onKeyPress="javascript:ret
runat="server"></asp:textb
Thanks all
To Explain:
You can add attributes to a control.. and the result will look like this (e.g. textbox)
<input name="name" ATTRIBUTE_NAME="ATTRIBITE_ VALUE">
You can add attributes to a control.. and the result will look like this (e.g. textbox)
<input name="name" ATTRIBUTE_NAME="ATTRIBITE_
ASKER
It is not working. The control looks like this:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="usercontrol.as cx.cs" Inherits="customer.UI.user control" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<div><asp:ListBox Rows="1" ID="keyValue" Runat="server" style="<%# DropStyle %>" /></div>
<div><asp:TextBox ID="textValue" Runat="server" style="<%# TextStyle %>" /></div>
Then in the ASPX page looks like this:
<div id="customerdiv">
customer:usercontrol id="L_SR_searchType" CssClass="box" runat="Server" />
</div>
also the entersubmits javascript is there
Then in the code behind:
public usercontrol L_SR_searchType;
L_SR_searchType.Attributes .Add("onKe yPress","j avascript: return enterSubmits(event, this)");
not working. Then in the source HTML:
<div><select name="L_SR_searchType:keyV alue" size="1" id="L_SR_searchType_keyVal ue" class="box">
<option value="CustomerName">Custo mer Name</option>
<option value="CustomerNumber">Cus tomer #</option>
<option value="CustomerOrder">Cust omer Order</option>
</select></div>
<div><input name="L_SR_searchType:text Value" type="text" id="L_SR_searchType_textVa lue" class="box" /></div>
</div>
The list is getting filled also in the code behind. So this is everything and that control is being used in many places. I am trying to get that entersubmits to fire off.
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="usercontrol.as
<div><asp:ListBox Rows="1" ID="keyValue" Runat="server" style="<%# DropStyle %>" /></div>
<div><asp:TextBox ID="textValue" Runat="server" style="<%# TextStyle %>" /></div>
Then in the ASPX page looks like this:
<div id="customerdiv">
customer:usercontrol id="L_SR_searchType" CssClass="box" runat="Server" />
</div>
also the entersubmits javascript is there
Then in the code behind:
public usercontrol L_SR_searchType;
L_SR_searchType.Attributes
not working. Then in the source HTML:
<div><select name="L_SR_searchType:keyV
<option value="CustomerName">Custo
<option value="CustomerNumber">Cus
<option value="CustomerOrder">Cust
</select></div>
<div><input name="L_SR_searchType:text
</div>
The list is getting filled also in the code behind. So this is everything and that control is being used in many places. I am trying to get that entersubmits to fire off.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In Page_Load()
{
L_SR_Search.Attributes.Add
}