Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access value of web control during server-side event

Status
Not open for further replies.

supermatchgame

Programmer
May 16, 2007
50
GB
Hi,

I have implemented this UI Spinner ( on a .aspx page. The spinner is built around an HTML <ul> called s3 on the page.

How can I access the value of this control on a server - side event? For example, in the Page_Load event I have tried doing

Code:
Dim k as String = Request.Form.Item("s3").ToString()

to try and find the value but I get an 'Object Reference not set to an instance of an Object' message back.

Can anyone let me know what to do?

Thanks.
 
You didn't post the HTML have, so I will assume it is similar to the code in the link you posted.

This is not a server side control, so you cannot reference it from the server side code. To do that, you need to add a runat="server" tag in the HTML of the control. Then you can reference it.

If the textbox is just an input of type="text"
dim var as string = me.<YourControlName>.Value
d
 
OK, runat = server. Thanks for the tip.

Problem now is that if I set the spinner <ul> to runat=server it doesn't render properly. And if I create a <label id="lbl" runat="server"> next to it with visible=false, and then try and write a javascript function to set the value of the label to be whatever the currently selected <ul> value is, the javascript doesn't recognise lbl at runtime.

I assume this is because the runat=server interferes with the javascript. Can anyone suggest a way around this? I'm really keen to add some javascript functionality to my asp.net site (yeah, I know the ajax controls exist but they're sub standard in a lot of cases) but am having problems integrating the two approaches.
 
I would set the runat=server on the input tag, which is the textbox, not on the <UL>

If you have specific javascript questions, I would post them in that fourm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top