User Controls...

  • Thread starter Thread starter Carlo Razzeto
  • Start date Start date
C

Carlo Razzeto

Is there a standard way in ASP.Net user controls to add your control value
to the Request.Form/QueryString collections with out having to reference an
internal control?

i.e. I know if you have user control ID'd "Foo" with a TextBox which
repersents its basic value called "Bar" you can reference

Request.Form["Foo:Bar:"];

What I'm looking for is:

Request.Form["Foo"];

I know I could just maintain the value my self through the ViewState and
create my own <input ...> tag called ID, but I was just wondering if ASP
provides a built in mechinism for this. Thanks,

Carlo
 
Hi,

Carlo said:
Is there a standard way in ASP.Net user controls to add your control value
to the Request.Form/QueryString collections with out having to reference an
internal control?

i.e. I know if you have user control ID'd "Foo" with a TextBox which
repersents its basic value called "Bar" you can reference

Request.Form["Foo:Bar:"];

What I'm looking for is:

Request.Form["Foo"];

I know I could just maintain the value my self through the ViewState and
create my own <input ...> tag called ID, but I was just wondering if ASP
provides a built in mechinism for this. Thanks,

Carlo

What is sent in the Request.Form collection is driven by the HTTP
protocol, which is relatively ancient. Only named "fields" are sent to
the server, and each name must be unique. If you have more than one
control, each with a "Foo" ID, then the uniqueness is not guaranteed,
and that will lead to problems. This is why the whole name, including
the parent container's name, is sent.

What you can do is add a method in the control itself, which delivers
the value, something like

string theValue = myControl.GetValue();

with (in the control)

public string GetValue()
{
if ( this.Page != null
&& this.Page.Request != null
&& this.Page.Request.Form != null
&& this.Page.Request.Form[ thetextField.ClientID ] != null )
{
return this.Request.Form[ thetextField.ClientID ];
}

return "";
}

(for example)

HTH,
Laurent
 
Thanks, that's about what I figured. My control actually will have a Text
property that functions much like GetValue in your example, but some of the
early .Net work on my companies system wasn't really written to take
advantage of things like the ViewState due to a lack of familiarity with
..Net amongst the developers that ported the app from classic ASP to ASP.Net,
so we really need Request.Form[...] to return the control value. So in the
end I am going to go ahead and manage the HTML for the input manually.

Carlo
 
Back
Top