Hi All,
My UserControl is having some linkbuttons. Whenever i click those linkbutton i need to show and hide some 'div' elements on the page on which im placing the usecontrol. What im doing is.
Code in LinkButton of UserControl
string scriptBlock ="";scriptBlock +="<script language='javascript' src='/system/Js/changeclass.js'>";
scriptBlock +="hidecontent123();"; // Here "hidecontent123 is the function that which im calling from the source file 'changeclass.js'.scriptBlock +="</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"doSomething", scriptBlock);
hidecontent123() function:
function hidecontent123(){
document.getElementById('previsible3').className='hidden';}
Now im placing this UserControl in the webpage. In this page im having the 'div' tag with id 'previsible3', that which im hiding using the javascript function. First of all its not even going in to the function 'hidecontent123()'.
With the above code im not able hide the 'div' tag that which i want. Can anyone plz help me out in this.
Thanks in Advance,
Rajak Shaik.
I can't see where you're adding the Javascript call to the LinkButton.
LinkButton1.Attributes("onclick") = "hidecontent123()"
Presumably 'hidden' is a CSS class with 'display:none;' or similar? In your function you could do this:
document.getElementById('previsible3').style.display = 'none';
Bear in mind that the rendered ID of your element will change in a user control, so you could add the ClientID to you function:
LinkButton1.Attributes("onclick") = "hidecontent123('" & previsible3.ClientID & "')"
Then:
function hidecontent123(theDiv)
{
document.getElementById(theDiv).style.display = 'none';
}
Also bear in mind that changes like these will not be persisted across postback.
(code untested!)
Forgot to mention, the LinkButton will cause a postback unless you prevent it. If it posts back, your changes (hiding the div) will be lost unless you save the current value(s) to a hidden field that can be accessed server-side.
To prevent postback:
LinkButton1.Attributes("onclick") = "return hidecontent123('" & previsible3.ClientID & "')"
function hidecontent123(theDiv)
{
document.getElementById(theDiv).style.display = 'none';
return false;
}
No comments:
Post a Comment