简体   繁体   English

后面的代码清除了updatepanel文本框后未调用Javascript

[英]Javascript not being called after an updatepanel textbox is cleared by code behind

I a web page that creates a note in a text area, On first time page load everything works fine. 我是一个在文本区域中创建注释的网页,在首次加载页面时一切正常。 Meaning it goes and does a post back and writes to a database. 意思是它去做回发并写到数据库。 Now , without reloading the page, on a second try if i change a drop down value and try to write to database it will not write a duplicate entry based on my code which is fine and i will clear out the note created in the text area (which is in an update panel) but for the next consecutive time if i change the drop down value, a java script that actually creates a note in the text area will not get fired and simply the text area is blank. 现在,在不重新加载页面的情况下,再次尝试如果我更改下拉值并尝试写入数据库,它将不会根据我的代码写重复的条目,这很好,并且我会清除在文本区域中创建的注释(位于更新面板中),但是如果我更改下拉值,则在下一个连续时间中,不会在文本区域中实际创建注释的Java脚本会被触发,并且文本区域为空白。 Any help is appreciated. 任何帮助表示赞赏。

   <asp:UpdatePanel> 
         <asp:TextBox ID="txtGenVVOE" name= "txtGenVVOE"  TextMode="MultiLine"
                                                runat="server"  style="font-size:  11px" rows="4" cols="44" Width="324px"></asp:TextBox></td></tr>
         <tr>  <td valign="top" align="center" width="50%"> 
  <asp:Button ID="btnCopy"
    class="btn"  runat="server" onmouseover="this.className='btn btnhov'"
                                onmouseout="this.className='btn'" style="background: silvergradient"   Text="COPY"
     OnClientClick="ClipBoard();return false;"
           ToolTip="Copy Text to ClipBoard"  />      /td></tr> <end update Panel>

I have a .js script to create the note called validate() which validates the fields before creating the note 我有一个.js脚本来创建名为validate()的注释,该脚本会在创建注释之前验证字段

function validate() {

create_note() // which creates a note based on all the fields on the form. create_note()//根据表单上的所有字段创建一个注释。 } }

So, as i have mentioned, this function validate is on button_click OnClientClick event and does not get called when button is clicked without reloading the page. 因此,正如我已经提到的,此函数validate在button_click OnClientClick事件上,并且在不重新加载页面的情况下单击按钮时不会被调用。 I need some help in understanding why the scripts gets called only once on load and not on subsequent time after an postback is done to an update panel. 我需要一些帮助来理解为什么在加载回发到更新面板后为什么在加载时只调用一次脚本,而在随后的时间不调用脚本的原因。 Thanks in advance. 提前致谢。

You will want to re-register the script in the code behind using ClientScript.RegisterStartUpScript ( http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx ) 您将需要使用ClientScript.RegisterStartUpScript( http://msdn.microsoft.com/zh-cn/library/z9h4dk8y.aspx )在后面的代码中重新注册脚本。

In the code that causes the postback you would want to do something like this: 在导致回发的代码中,您需要执行以下操作:

Dim script as string = "<script type=""text/javascript"">validate();</script>"
ClientScript.RegisterStartupScript(me,me.gettype(),"NameYourScript",script,false)

If RegisterStartupScript doesn't hit try RegisterClientScriptBlock ( http://msdn.microsoft.com/en-us/library/btf44dc9.aspx ) 如果RegisterStartupScript没有命中,请尝试RegisterClientScriptBlock( http://msdn.microsoft.com/en-us/library/btf44dc9.aspx

I can't remember which one gives me trouble when it comes to update panels. 我不记得在更新面板时哪一个给我带来了麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM