Forcing __DoPostBack script to be generated dynamically?

  • Thread starter Thread starter Rick Strahl [MVP]
  • Start date Start date
R

Rick Strahl [MVP]

I have a situation where I dynamically generate a control onto a page via
page insertion in the Render method. I'm handling everything manually on
this control because there's no knowledge at all about the page as this is a
generic framework level Page. It appears to not be possible to add the
control into the Controls collection of the page (only into some other
container which is an unknown to this generic page).

Anyway I have all of this working by forcing my control to fire a Postback
event 'manually' (I generate that code). This all works fine fine IF the
handler is there. IOW, if there's some control on the form that requires
AutoPostback or implicitly uses it like a Linkbutton control.

However, I can't figure out how to dynamically trigger the form to render
the handler if this is not the case.

I've tried to create a control manually and then pass that to
RegisterRequiresPostBack() but it doesn't generate the script block.

Is there some other way to force the Page to generate the __DoPostBack()
function?

For that matter I might be missing something - is it possible to add a
control to a page (not a user control, but a stock control like Label)
without inserting it into a container? It sure would make life easier if I
could just insert a link button instead of genering the HTML manually <g>...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
 
Hi,

you can add controls dynamically to your from but you should do it
before control tree build like page_load event. you can also set
__Dopostback by using GetPostBackEventReference :

TextBox otxt = new TextBox();
otxt.Text = "natty";
otxt.Visible = true;
otxt.AutoPostBack = true;
otxt.ID = "txtDyna";
otxt.TextChanged += new EventHandler( MyHandleFunction );
otxt.Attributes.Add("onMouseOver",this.GetPostBackEventReference(otxt,"b
obo"));
this.FindControl("Form1").Controls.Add(otxt);


Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top