ClientScript.RegisterStartupScript问题 [英] problem with ClientScript.RegisterStartupScript
问题描述
好吧,我有2页page1和page2
单击网格按钮后从page1加载page2作为窗口
在第2页中,我有3个控件:TextBox和2 Button Save and Close
这是下面的代码
well I have 2 pages page1 and page2
from page1 after clicking on grid button loads page2 as window
In page 2 I have 3 control: TextBox and 2 Button Save and Close
here is code below
<script type="text/javascript">
function returnToParent(result) {
var arg = new Object();
arg.result = result;
arg.text = document.getElementById("txtComment").value;
var wnd = GetRadWindow();
wnd.close(arg);
}
function GetRadWindow() {
var mwnd = null;
if (window.radWindow) mwnd = window.radWindow;
else if (window.frameElement.radWindow) mwnd =
window.frameElement.radWindow;
return mwnd;
}
</script>
<asp:TextBox ID="txtComment" TextMode="MultiLine" runat="server"
Width="700px" Height="60px" />
<asp:LinkButton ID="lnkSave" runat="server" Text="Save" Width="100%"
CssClass="white" onclick="lnkSave_Click" />
<asp:LinkButton ID="lnkClose" runat="server" Text="Close" Width="100%"
CssClass="white" CausesValidation="false"
OnClientClick="returnToParent(0); return false;" />
和背后的代码
and Code Behind
protected void lnkSave_Click(object sender, EventArgs e) {
if(!string.IsNullOrEmpty(txtComment.Text))
{
// code
ClientScript.RegisterStartupScript(this.GetType(),
"CloseWindow", "returnToParent(1)", true);
}
else {
ClientScript.RegisterStartupScript(this.GetType(),
"CloseWindow", "returnToParent(1)", true);
}
}
如您看到的关闭按钮,我调用javascript函数 returnToParent(result)并设置resalt 0
它扭曲并且不回发
现在我想如果TextBox.Text为空,请在后面的代码中检查它
if(!string.IsNullOrEmpty(txtComment.Text))
如果为空,则转到else语句,然后尝试执行该操作,以免在注册脚本后回发
但是当文本框为空时我单击保存"按钮时会出现麻烦,它会再次回发
我该怎么做而不回发? :(
as you see close button I call javascript function returnToParent(result) and set resalt 0
it warks and does not postback
now I want to do if TextBox.Text is empty that I check it in code behind
if(!string.IsNullOrEmpty(txtComment.Text))
if it''s empty it goes to else statement there I try to do it so that not postback with registering script
but there is trouble when I click save button when textbox is empty it postbacks again
How can I do it that not postback?? :(
推荐答案
Page.RegisterStartupScript("name", "<script>IsEmpty();</script>");
javascript函数
javascript function
<br />
function IsEmpty()<br />
{<br />
var a=
get(clientId+txtComment).value<br /> .<br /> .<br /> .<br /> <br /> }
get(clientId+txtComment).value<br /> .<br /> .<br /> .<br /> <br /> }
在javascript
中编写您需要的代码
在这里,您应该在controlid之前添加clientId以获取控件
希望对您有帮助.
write the code you need here in javascript
Here you should add the clientId before the controlid for getting the control
I hope this may help you..
如果您不希望在文本框为空时进行回发,则需要在客户端进行检查.
If you don''t want the postback to occur when the textbox is empty then you need to check it at the client.
这篇关于ClientScript.RegisterStartupScript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!