积极答复者
[玻璃鱼V]关于模态窗体回传值后插入指定Textbox控件原光标处的问题

问题
-
使用了母版页的ASPX页面(A.ASPX)上有1个asp:Button控件(btAdd)和1个asp:TextBox控件(tbText),点击btAdd打开模态窗体(B.ASPX)并根据选择返回值:
Response.Write(" <script type='text/javascript'>var sUrl=window.showModalDialog('B.aspx','','dialogWidth=800px;dialogHeight=600px') </script>");
之后在A页面接受回传的值并将转化后的字符串插入到tbText中光标位置.
--------------------------------------------------------------------------------------
就这么一个功能,研究2天了还是没结果.在A页面中取得回传值这一步已经没问题了,问题出现在将值插入到asp:TextBox控件的光标处.
谁能给个完整的代码阿~
先谢过热心回答的各位了~
答案
全部回复
-
在CS页面中:
protected void btAddPhotoFromGallery_Click(object sender, EventArgs e)
{
string str1 = "GetTextLength()";
ClientScriptManager cs1 = Page.ClientScript;
cs1.RegisterStartupScript(this.GetType(), "", str1, true);
Response.Write("<script type='text/javascript'>var sPhotoUrl=window.showModalDialog('PhotoView.aspx','','dialogWidth=800px;dialogHeight=600px')</script>");
string str2 = "SetPhoto()";
ClientScriptManager cs2=Page.ClientScript;
cs2.RegisterStartupScript(this.GetType(),"",str2,true);
}
在ASPX页面中:
<script type="text/javascript">
var obj;
var i;
var s;
function GetTextLength()
{
obj=document.getElementById("<%=tb_Write_Head.ClientID %>");
obj.focus();
var r = document.selection.createRange();
s = obj.value;
r.collapse(false);
r.setEndPoint("StartToStart", obj.createTextRange() ); //出错行
i = r.text.length;
}
function SetPhoto()
{
obj.value = s.substr(0,i) + "111" + s.substr(i,s.length);
}
</script>
运行后提示"参数无效".
对JS是一点也不了解,还是得请孟老师多指点了- - -
window.showModalDialog在客户端执行就可以了,没有必要放在服务器端的Click.
<script type="text/javascript">
function openDial()
{
GetTextLength()
var sPhotoUrl=window.showModalDialog('PhotoView.aspx','','dialogWidth=800px;dialogHeight=600px')
SetPhoto()
}
Page_Load:
btAddPhotoFromGallery.OnClientClick="openDial();return false;";//OnClientClick只有asp.net 2.0之后才有的,2.0之前使用btAddPhotoFromGallery.Attributes.Add("onclick","openDial();return false;");
孟宪会