[Mono-devel-list] RE: [Mono-list] How to maintain values in a HtmlSelect when modifying the content with javascript ?

John BouAntoun jbouantoun at rogen.com.au
Thu Dec 11 18:37:03 EST 2003


I suggest looking at the samples in the xsp project for drop down list.

If you are wanting to work with any html form controls on both the server side (C#) and the client side (javascript) then you really should look at using controls in the System.Web.UI.WebControls namespace and not the System.Web.UI.HtmlControls.

Controls in the System.Web.UI.WebControls namespace still render to the page as normal html form controls,
so you should be able to access them using javascript on the client.

A good tip to keep in mind when using javascript on System.Web.UI.WebControls, is that each control has a ClientID property that is the string value of the client side control's id.

So if you had a drowdown list called listbox1, when writing javascript to the page you would do something like this:

private void PageLoad()
{
	if(!IsPostback)
	{
		// build the client script to display the client side select item from the listbox1 object
		clientscript = "<script>alert('this is the client side list box control: ' + ";
		clientscript += "document.getElementById('"
		clientscript += listbox1.ClientID
		clientscript += @"'));</script>";

		// register this script to run once the program has started
		Page.RegisterStartupScript("listbox1", clientscript);
		
	}
}

Hopefully that example shows you how interactions between client and server side work.

JBA

-----Original Message-----
From: Tiago Lima [mailto:tiago.lima at vianw.pt]
Sent: Friday, 12 December 2003 10:15 AM
To: John BouAntoun; mono-devel mailing list; mono-list mailing list
Subject: Re: [Mono-list] How to maintain values in a HtmlSelect when
modifying the content with javascript ?


Thanks, I will see that..

But in that case, how do I handle that in javascript, just like a <select>?

	Tiago Lima

On Thursday 11 December 2003 23:06, John BouAntoun wrote:
> Tiago,
>
> If you want to use the equivalent of a Html Select element, that is able to
> have it's values handle in C# on the server (i.e. on page load and after a
> postback etc) then why not simply use the
> System.Web.UI.WebControls.DropdownList item?
>
> You can bind the dropdown list option elements to records in a dataview or
> dataset and you can also get / set the selected index.
>
> I'm pretty sure that's what you are looking for.
>
> JBA
>
>
>
> -----Original Message-----
> From: Tiago Lima [mailto:tiago.lima at vianw.pt]
> Sent: Friday, 12 December 2003 10:00 AM
> To: mono-devel mailing list; mono-list mailing list
> Subject: [Mono-list] How to maintain values in a HtmlSelect when
> modifying the content with javascript ?
>
>
> Hi,
>
> I've a question regarding whether an HtmlSelect maintains the "options"
> inside it when these options get modified in javascript. I dont know how
> Microsoft .NET handles this...
>
> I have two HtmlSelects, one of them starts empty and the other one have all
> the elements... The user moves around the elements from one to another and
> then posts the result... I want to know the elements in the first
> HtmlSelect... How do I do this?
>
> If I select one of the elements in the first HtmlSelect then I get an
> error:
>
> System.IndexOutOfRangeException: Array index is out of range
> in [0x00074] (at /home/duncan/Mono/mcs/class/System.Web/
> System.Web.UI.HtmlControls/HtmlSelect.cs:209)
> System.Web.UI.HtmlControls.HtmlSelect:System.Web.UI.IPostBackDataHandler.Lo
>adPostData (string,System.Collections.Specialized.NameValueCollection)
> i
> ...
>
> this is because the HtmlSelect has no elements in the beggining !
>
> Is the System.Web.UI.WebControls.ListBox controls doing this?
>
> Thanks in advance,
> 	Tiago Lima
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list




More information about the Mono-devel-list mailing list