本文介绍了如何访问updatepanel外部的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在更新面板中有一个按钮(比如提交按钮),它显示点击事件的模态弹出窗口(仅在同一更新面板内的模态弹出窗口)。我在更新面板外面有几个文本框。文本框不能在面板内,因为它包含的代码不能在更新面板中运行。当我点击提交按钮时,它显示模式弹出框,其中包括两个按钮(btnyes和btnNo)。我已经为少数文本框调用了cleartext()函数(它清除了所有文本框文本),并且我还会从btnyes click事件中获取一些从数据库到其他文本框的值。这里的问题是,当我点击我的btnyes时,我无法清除我的文本框。是因为,我的文本框在更新面板之外。我怎样才能清除我的文本框? 我的提交按钮和modalpopextender在更新面板的内容模板中,我为btnyes添加了触发器解决方案 首先在页面的头部写一个javascript函数。 function setTextBoxValues(firstValue,secondValue) { document .getElementById(' FirstTextBoxID')。value()= ' '; // 清除第一个文本框的文本 document .getElementById(' SecondTextBoxID')。value()= ' '; // 清除第二个文本框的文本 document .getElementById(' FirstTextBoxID')。value()= firstValue; // 设置新值 document .getElementById( SecondTextBoxID')。value()= secondValue; // 设置新值 } 点击更新面板内的按钮写下这一行 protected void Button1_Click( object sender,EventArgs e) { string firstValueFromDatabase = valueFromDatabase; // 从数据库获取值 string secondValueFromDatabase = valueFromDatabase; // 从数据库获取值 ScriptManager.RegisterClientScriptBlock( this , this .GetType(), ClearControls, setTextBoxValues(' + firstValueFromDatabase + ',' + secondValueFromDatabase + ');, true ); } I have a button (say submit button) within an update panel which shows modal popup on click event(Modal popup inside same update panel only). I have few textboxes outside the update panel. The text boxes can''t be inside the panel because it contains code that doesn''t run within an update panel. When i click submit button it shows modal pop box which includes two buttons(btnyes and btnNo). I have called "cleartext()" function (which clears all the text box text) for few textbox and also i ll get some values from database to some other textbox in btnyes click event. The problem here is i can''t clear my text box when i click my btnyes. IS it because ,my textboxes are outside the update panel. how can i clear my textboxes? My submit button and modalpopextender was with in content template of update panel and i added trigger for btnyes 解决方案 First write a javascript function in the head of your page.function setTextBoxValues(firstValue,secondValue){document.getElementById('FirstTextBoxID').value() = '';//to clear text of first text boxdocument.getElementById('SecondTextBoxID').value() = '';//to clear text of second text boxdocument.getElementById('FirstTextBoxID').value() = firstValue;//to set new valuedocument.getElementById('SecondTextBoxID').value() = secondValue;//to set new value}On click of button inside update panel write this lineprotected void Button1_Click(object sender, EventArgs e){string firstValueFromDatabase = "valueFromDatabase";//get value from databasestring secondValueFromDatabase = "valueFromDatabase";//get value from databaseScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClearControls", "setTextBoxValues('" + firstValueFromDatabase + "','" + secondValueFromDatabase + "');", true);} 这篇关于如何访问updatepanel外部的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 19:51