1

I have a custom server control which renders some HTML on the aspx page it is added.

    protected override void RenderContents(HtmlTextWriter output)
    {
        Text = GetHTMLContent();

        output.Write(Text);
    }

the GetHTMLContent() retuns some HTML, say

<div id="panel" onMouseOver="hide"><table><tr><td>Something Here</td></tr></table></div>

And I have a javascript file which is an embeded resource in this server control. This javascript file contains a function, say

    function hide(){
         document.getElementById("panel").visible = false;
    }

I add the custom control in an aspx page like this

<cc1:CControl ID="Div" runat="server"></cc1:CControl>

now when I open in browser, the HTML contents are rendered fine, but javascript needs to be working.

My question is how can we make the function, which is in javascript file embeded in custom control, work on a aspx page where the custom control will be loaded?

Thanks

2 Answers 2

1

There are several ways. First can be to have an OnClientHide="hide" property, where this property defines the name of a method to call as a callback. Your control can pass this to the onmouseover client event handler during rendering.

Or: have your control write javascript to the browser, like this: http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

EDIT

Also check out this example: http://www.karpach.com/Custom-ASP-NET-server-control-with-embedded-resources.htm

Sign up to request clarification or add additional context in comments.

2 Comments

I guess I could not ask the question properly. Now I revised it. "My question is how can we make the function, which is in javascript file embeded in custom control, work on a aspx page where the custom control will be loaded?"
This is a good example of the process: karpach.com/…
0

Besides what Brian Mains said, you javascript to hide is incorrect. It should be:

function hide()
{
    document.getElementById("panel").style.display = "none";
    OR
    document.getElementById("panel").style.visibility = "hidden";
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.