Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi everyone,

 

I'm making a simple user control that encapsulates some javascript that I found online (the javascript is a pop-up calendar that writes the selected date to an html input tag). The script will not work if runat="server" is added to the tag, nor will it work if I try to use a textbox instead. I'd like to be able to expose the selected date as a property of the control I'm making, but I'm having trouble finding a way to access the value of the input tag programatically.

 

Any ideas?

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted
That's a good start. I could do something like that in javascript, and then execute that script inside an event handler. But I'm not trying to set the input's property, I'm trying to expose the input's value as a read-only property of the containing .ascx control. If I could execute the javascript in C# or VB.NET and have it return a value (most likely a string), that would be ideal.

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted

Oh, I see what you mean right now. It sounds like the input control is a pure HTML and not an asp:TextBox server control.

 

When your control loads you simply need to check the IsPostBack variable. If it's true then the control is being rendered due to the user submitting the form back to the server and the form data will be available to you. All HTML controls that are within the <form> tag can be accessed through Page.Request.Form using the name attribute for the control (not the ID attribute).

 

Option 1) Just call Request.Form["MyText"]

 

Option 2) You can make the properties of the HTML input available programmatically with:

<input id="MyText" type="text" runat="server" />

Option 3) You could just make it into a server control:

<asp:TextBox ID="MyText" runat="server" />

With 2 and 3 you can access the text with:

MyText.Text

 

You can then use any of these options to expose a read-only property:

public string MyProperty
{
  get { return MyText.Text; }
}

Posted
I got it working with an asp textbox. Thanks for your help!

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...