yaniv said:
how do i pass a parameter to user control?
So, source is a string property of your topmenu class?
1. add a HTMLInputHidden to your class def.
2. Make a property to set its value
3. Define an event for it to load its value into view state on render (not sure if this is the best way to do this, I couldnt find any documentation or examples but this should work. . . I forget why I did this and not just set view state in the property, but there was a reason! I gotta practice documentation!!!)
4. Redefine your constructor to set the hidden control's event and add the hidden control to the Wrapping class' Controls Property
5. override the oninit to define a uniques ID for the hidden control. Do this in on init as you are using the wrappers Unique ID as a base and it isnt set until after init is called
6. Override the wrapper's render method to render the Hidden input. . . add a parameter runat=server before rendering
PHP:
public class TopMenu : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.HtmlControls.HtmlInputHidden source = new System.Web.UI.HtmlControls.HtmlInputHidden();
protected void Source_PreRender(object sender, EventArgs e)
{
ViewState[((System.Web.UI.HtmlControls.HtmlInputHidden)(sender)).ID] = ((System.Web.UI.HtmlControls.HtmlInputHidden)(sender)).Value;
source.Text = ((System.Web.UI.HtmlControls.HtmlInputHidden)(sender)).Value;
}
public String Source
{
get
{
return source.Value;
}
set
{
source.Value = Value;
}
}
public TopMenu(): base()
{
source.PreRender += new EventHandler(Source_PreRender);
Controls.Add(source);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
source.ID = this.UniqueID + "Source";
}
protected override void Render(HtmlTextWriter output)
{
source.Attributes.Add("runat","server");
source.RenderControl(output);
base.RenderControl(output);
}
}
This code is hacked from something I just wrote for a job. . . might not work as written here, but I think you will get the idea. The numbered items at the top need to be addressed for the class to work.
I have been preparing a tutorial on developing a WebControl for rendering an <OBJECT> element. If anyone has any input as to working with the ViewState of the wrapped element - please reply!!!