开发者

how can i use the onkeyup event in textbox?

hey guys,i want your help!this is my code:

<%
string a=Request.Params["a"]; 
%>
<form id="form1" runat="server">
    <div>
    &nbsp;
  <input type="text" id="cc" runat="server" visible="false"/>
  <input type="text" id="aa" runat="server" onkeyup="key(document.all.aa.value,'<%=a; %>');"/>

the 'a' is a parameter request from another page.now in this page i hava a textbox and i give its a开发者_StackOverflow onkeyup event. then 'key()' is a function include two parameter:one is itself's value and another is 'a',but there is an error:Server tags can not contain <% ...%> Structure. what can i do? i don't know if you understand me,because my English is very poor!


You are approaching it in the wrong way.You cant just data bid to any text box a variable. You need a property so first you define a property in Code behind

public string ParamsA{get;set;}

Then you use the following to set Request.params into ParamsA property, and then Bind it to a input Text HTML element. Then you pass the value property of the HTML element to the javascript.

<%= Name=Request.Params["a"];  %>
  <input type="text" id="id2" value='<%= Name %>' />
  <input type="text" id="cc" runat="server" visible="false"/><br />
  <input type="text" id="prev" value="Prev Value" />
  <input type="text" id="aa" runat="server" onkeyup="key( prev.value,id2.value);" />

In the javascript you can access as

 function key(x,y) {

            alert("X =" + x + "  Y= " + y);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜