在return语句后调用javascript函数
问题描述:
大家好
请帮我解决以下问题。
我已提交表格有3个选项 - 1.文字,2.视频,3.图像
如果用户从上面选择任何一个选项,那么相应的div将会打开。
我的javascript函数是 -
Hi All
Please help me with below issue.
I have submit form in which there are 3 options- 1. Text,2.Video,3.Image
if user select anyone option from above then respective div will open.
my javascript function is-
function fn_radio()
{
//var form1="ContentPlaceHolder1";
var form1="ctl00_ContentPlaceHolder1";
//alert("hi");
if(document.getElementById(form1+'_rdo_text').checked)
{
//alert("text");
document.getElementById("hidden_radio").value= "text";
document.getElementById("div_text").style.display="block";
document.getElementById("div_video").style.display="none";
document.getElementById("div_image").style.display="none";
document.getElementById("plus1").style.display="none";
}
if(document.getElementById(form1+'_rdo_video').checked)
{
//alert("video");
document.getElementById("hidden_radio").value= "video";
document.getElementById("div_video").style.display="block";
document.getElementById("div_text").style.display="none";
document.getElementById("div_image").style.display="none";
document.getElementById("plus1").style.display="none";
}
if(document.getElementById(form1+'_rdo_image').checked)
{
//alert("image");
document.getElementById("hidden_radio").value= "images";
document.getElementById("div_text").style.display="none";
document.getElementById("div_video").style.display="none";
document.getElementById("div_image").style.display="block";
document.getElementById("plus1").style.display="block";
}
return true; // return false to stop postback
}
现在问题是 - 我正在检查文件后面的代码中的图像大小。如果它返回false,那么我想调用上面的函数。
该怎么办?
请帮帮我...
Now the problem is- i am checking image size in code behind file. n if it returns false then i want to call above function.
what to do?
Pls help me out...
答
将此行添加到您要调用js函数的代码中: -
Add this line to your code from where you want to call js function:-
ScriptManager.RegisterStartupScript(this, GetType(), "radioEle", "fn_radio();", true)
Hi Sweetynewb,好时光。 ..
你可以尝试这个策略:
***在服务器端(代码隐藏) file / .cs文件)
Hi Sweetynewb , good time...
you can try this strategy:
*** In Server side ( Code-Behind file / .cs file )
protected void BtnSubmit_clicked (object sender , eventargs e)
{
// check your image size here
if ( size is okay)
// do some thing
else
{
string str = "fn_radio();";
ClientScript.RegisterStartupScript(this.GetType , "myScript" , str , true);
}
}
在你的代码中包括以下条件的条件:
In your code behind include the following code on condition:
System.Text.StringBuilder JSText = new System.Text.StringBuilder();
JSText.Append(@"<script language='javascript'>");
JSText.Append(@"fn_radio();");
JSText.Append(@"</script>");
if (!ClientScript.IsStartupScriptRegistered("MyScript"))
{
ClientScript.RegisterStartupScript(this.GetType(), "MyScript", JSText .ToString());
}
如果您使用的是AsyncPostback,则必须使用ScriptManager.RegisterStartupScript
If you are using AsyncPostback, you will have to use ScriptManager.RegisterStartupScript