How to put hidden input tag to the page?

How to put hidden input tag to the page?

am 26.01.2008 19:24:41 von momonga

Hi
I'm really new to ASP.NET and would be very grateful any advice.
I want to search a database and put the each results into the value of
hidden field to refer them from javascript.
but I don't know how to it at all..


I'm thinking about the following approach.
(1) Search the database at Page_Load().
(2) Put the following html to the page somehow.
""
""
""
..
..
..
(3) Use the values from javascript as following.
function func()
{
totalRows = document.getElementById("totalrows").value;
for(i = 0 ; i < totalRows ; i++)
{
var str_id = "row" + i;
var x = document.getElementById(str_id);
alert(x.value);
}
}

My question is...
(a) Is my way good in the ASP.NET custom?
(b) How to put some hidden input tags to the page?(step(2))

Re: How to put hidden input tag to the page?

am 26.01.2008 19:42:31 von mark

"momonga" wrote in message
news:bb64798a-0b17-4883-a867-a39c9f9a6cb6@v67g2000hse.google groups.com...

> I'm really new to ASP.NET and would be very grateful any advice.
> I want to search a database and put the each results into the value of
> hidden field to refer them from javascript.
> but I don't know how to it at all..
>
> I'm thinking about the following approach.
> (1) Search the database at Page_Load().

That's probably the best solution, but you might want to search the database
only when the page first loads, not if/when it loads as a result of a
postback... In which case, simply surround the code which searches the
database with

if (!IsPostback)
{
// do the search here
}

> (2) Put the following html to the page somehow.
> ""
> ""
> ""

How many rows might there possibly be...?

Also, ASP.NET has its own webcontrol version of the above:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webco ntrols.hiddenfield.aspx

> (3) Use the values from javascript as following.
> function func()
> {
> totalRows = document.getElementById("totalrows").value;
> for(i = 0 ; i < totalRows ; i++)
> {
> var str_id = "row" + i;
> var x = document.getElementById(str_id);
> alert(x.value);
> }
> }

Hmm - do you *really* want to fire a load of alerts when the page loads?
That would really irritate me!

> (a) Is my way good in the ASP.NET custom?

Difficult to tell without knowing what you're actually trying to achieve
with this...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: How to put hidden input tag to the page?

am 26.01.2008 20:23:51 von momonga

Hi!
Thanks for the advice.

> That's probably the best solution, but you might want to search the databa=
se
> only when the page first loads, not if/when it loads as a result of a
> postback... In which case, simply surround the code which searches the
> database with
>
> if (!IsPostback)
> {
> =A0 =A0 // do the search here
>
> }
I think I need this.Thanks!

> How many rows might there possibly be...?
In the most case, it will be less than about 10 or so.
It will be less than about 100 or so at maximum.

> Hmm - do you *really* want to fire a load of alerts when the page loads?
> That would really irritate me!
No.I don't want to call alert actually.
To tell the truth, In my page, there will be an ActiveX control and I
want to call the method with x.value.

Thansk!

Re: How to put hidden input tag to the page?

am 26.01.2008 20:57:26 von mark

"momonga" wrote in message
news:08f10cdd-323c-40f6-9313-da09a99c1e02@c4g2000hsg.googleg roups.com...

>> How many rows might there possibly be...?
> In the most case, it will be less than about 10 or so.
> It will be less than about 100 or so at maximum.

OK.

>> Hmm - do you *really* want to fire a load of alerts when the page loads?
>> That would really irritate me!
> No.I don't want to call alert actually.
> To tell the truth, In my page, there will be an ActiveX control and I
> want to call the method with x.value.

What does the ActiveX control do...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Re: How to put hidden input tag to the page?

am 26.01.2008 21:47:53 von momonga

> What does the ActiveX control do...?
The ActiveX control is streaming player and requests certain server
some contents.
I need to pass him the content identifier.

Now, I find "Page.ClientScript.RegisterHiddenField()" function.
And I worked it out.

Thanks a lot!

Re: How to put hidden input tag to the page?

am 26.01.2008 22:22:02 von mily242

Howdy,

No need for using hidden fields, you can render the values directly to your
script:



-- code behind --

protected string DelimitedValues = "1, 2, 10, 'stringValue', 'whatever'";

// or even better populated once and stored in the viewstate

protected vpoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// retreive values from database
DelimitedValues = "'1','2','aaa'";
}
}

protected string DelimitedValues
{
get
{
return (string) ViewState["DelimitedValues"];
}
set
{
ViewState["DelimitedValues"] = value;
}
}


Hope this helps
--
Milosz


"momonga" wrote:

> > What does the ActiveX control do...?
> The ActiveX control is streaming player and requests certain server
> some contents.
> I need to pass him the content identifier.
>
> Now, I find "Page.ClientScript.RegisterHiddenField()" function.
> And I worked it out.
>
> Thanks a lot!
>
>
>
>
>

Re: How to put hidden input tag to the page?

am 26.01.2008 23:09:53 von momonga

I was looking for such a solution.
Thanks for the great tips!

Re: How to put hidden input tag to the page?

am 27.01.2008 02:14:06 von mark

"momonga" wrote in message
news:6805db16-1f67-42fd-bc9c-38cd22cf5a25@s12g2000prg.google groups.com...

>> What does the ActiveX control do...?
> The ActiveX control is streaming player and requests certain server
> some contents.
> I need to pass him the content identifier.
>
> Now, I find "Page.ClientScript.RegisterHiddenField()" function.
> And I worked it out.

Ah... As has been mentioned, no need at all for hidden fields here...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net