Link to home
Start Free TrialLog in
Avatar of sbornstein2
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:textValue" type="text" value="1004434" id="L_SR_searchType_textValue" 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:return enterSubmits(event, this)"
                                                                        runat="server"></asp:textbox>

Thanks all
Avatar of nehaya
nehaya

Add attribute in code like this:
In Page_Load()
{
     L_SR_Search.Attributes.Add("onKeyPress","javascript:return enterSubmits(event, this)");
}
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">
Avatar of sbornstein2

ASKER

It is not working.  The control looks like this:

<%@ Control Language="c#" AutoEventWireup="false" Codebehind="usercontrol.ascx.cs" Inherits="customer.UI.usercontrol" 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("onKeyPress","javascript:return enterSubmits(event, this)");

not working.  Then in the source HTML:
<div><select name="L_SR_searchType:keyValue" size="1" id="L_SR_searchType_keyValue" class="box">
      <option value="CustomerName">Customer Name</option>
      <option value="CustomerNumber">Customer #</option>
      <option value="CustomerOrder">Customer Order</option>

</select></div>
<div><input name="L_SR_searchType:textValue" type="text" id="L_SR_searchType_textValue" 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.
ASKER CERTIFIED SOLUTION
Avatar of nehaya
nehaya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial