Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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-
C#
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
}


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...
Posted

Add this line to your code from where you want to call js function:-

ScriptManager.RegisterStartupScript(this, GetType(), "radioEle", "fn_radio();", true)
 
Share this answer
 
v2
Comments
Ali Reza Barkhordari 22-Apr-13 8:34am    
Note1 :It's better to use ClientScript , isn't ? Note 2: 'Me' is in VB not C#
TrushnaK 22-Apr-13 8:44am    
I used that because:-

You've pretty much identified the primary difference. The ScriptManager is meant to be used with async postbacks, which is why it works with the UpdatePanel. The ClientScript class is for synchronous postbacks. So, if you're going to be posting back from an UpdatePanel, be sure to use the ScriptManager instead of ClientScript.
Sweetynewb 22-Apr-13 8:51am    
yes but where should i write this? bcoz after return statement it exits codebehind funcion
TrushnaK 22-Apr-13 8:55am    
Before exit of your function. remember it calls after code behind function.
Hi Sweetynewb , good time...

you can try this strategy:

*** In Server side ( Code-Behind file / .cs file )

C#
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);
}
}
 
Share this answer
 
In your code behind include the following code on condition:
C#
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());
}


If you are using AsyncPostback, you will have to use ScriptManager.RegisterStartupScript
 
Share this answer
 
Instead of returning false from code behind,call this function like...
JavaScript
Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "checkRadio", "fn_radio();");
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900