• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

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
0
sbornstein2
Asked:
sbornstein2
  • 3
1 Solution
 
nehayaCommented:
Add attribute in code like this:
In Page_Load()
{
     L_SR_Search.Attributes.Add("onKeyPress","javascript:return enterSubmits(event, this)");
}
0
 
nehayaCommented:
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">
0
 
sbornstein2Author Commented:
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.
0
 
nehayaCommented:
1- Change the control source and add OnKeyPress into your control code!
(The one who made the control should add such thing, if not, do it yourself and add )

OR
2- Call your textValue directly like this:
textValue.Attributes.Add("XXX","XXX" );
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now