Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to implement a "value" property for Web User Controls?

Reply
Thread Tools

How to implement a "value" property for Web User Controls?

 
 
Harvey Triana
Guest
Posts: n/a
 
      04-23-2007
Hi--
Sample. When i write something like:
<input type="button" name="btnSend" value="Send"
onclick="callSomeTask(getElementById('myControl'). value );return false;
/>

I can run some cliente code if "myControl" is an Asp Textbox;
getElementById('myControl').value get current Text of Textbox

If i write a Web User Control, i dont know how to implemente the property
"value", value runs for the cliente not in server.

Thanks,
<Harvey Triana />


 
Reply With Quote
 
 
 
 
Ray Costanzo
Guest
Posts: n/a
 
      04-23-2007
I'm not certain I understand what you're asking, but I'll take a guess. You
need the client ID an html element that asp.net generates, correct? There
is a .ClientID property that will expose that. So, you have to pull that
client ID from your code behind and inject it into your client-side code in
someway. You can build strings in your codebehind containing javascript
functions, but I personally find this to be a PITA. So, I use a Literal
that's hidden and put my client-side code in there, alter it as needed, and
then register the text of it. This makes for a better Visual Studio
experience. Here's a sample:




codebehind:
protected void Page_Load(object sender, EventArgs e)
{
litClientScript.Text = litClientScript.Text.Replace("%someTextBox%",
someTextBox.ClientID);
Page.RegisterClientScriptBlock("JS", litClientScript.Text);
}


..aspx:



<asp:textbox id="someTextBox" runat="server" text="here's some text" />
<input type="button" onclick="giveIt();" value="Click me" />

<asp:literal id="litClientScript" runat="server" visible="false">
<script type="text/javascript">
function giveIt() {
alert(document.getElementById('%someTextBox%').val ue);
}
</script>
</asp:literal>


Ray at work


"Harvey Triana" <> wrote in message
news:...
> Hi--
> Sample. When i write something like:
> <input type="button" name="btnSend" value="Send"
> onclick="callSomeTask(getElementById('myControl'). value );return false;
> />
>
> I can run some cliente code if "myControl" is an Asp Textbox;
> getElementById('myControl').value get current Text of Textbox
>
> If i write a Web User Control, i dont know how to implemente the property
> "value", value runs for the cliente not in server.
>
> Thanks,
> <Harvey Triana />
>


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      04-23-2007
this will depend on what dom elements your user control renders.

-- bruce (sqlwork.com)

Harvey Triana wrote:
> Hi--
> Sample. When i write something like:
> <input type="button" name="btnSend" value="Send"
> onclick="callSomeTask(getElementById('myControl'). value );return false;
> />
>
> I can run some cliente code if "myControl" is an Asp Textbox;
> getElementById('myControl').value get current Text of Textbox
>
> If i write a Web User Control, i dont know how to implemente the property
> "value", value runs for the cliente not in server.
>
> Thanks,
> <Harvey Triana />
>
>

 
Reply With Quote
 
Harvey Triana
Guest
Posts: n/a
 
      04-23-2007
> this will depend on what dom elements your user control renders.
A sample, please...

<Harvey Triana />

"bruce barker" <> escribió en el mensaje
news:...
> this will depend on what dom elements your user control renders.
>
> -- bruce (sqlwork.com)
>
> Harvey Triana wrote:
>> Hi--
>> Sample. When i write something like:
>> <input type="button" name="btnSend" value="Send"
>> onclick="callSomeTask(getElementById('myControl'). value );return
>> false; />
>>
>> I can run some cliente code if "myControl" is an Asp Textbox;
>> getElementById('myControl').value get current Text of Textbox
>>
>> If i write a Web User Control, i dont know how to implemente the property
>> "value", value runs for the cliente not in server.
>>
>> Thanks,
>> <Harvey Triana />



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Named User Licensing - how to implement? element77 Java 0 07-26-2007 06:40 PM
Custom object with a System.Web.Security.MembershipUserCollection property - "implement a default accessor" error justin.drerup@gmail.com ASP .Net Web Services 0 05-20-2006 08:38 AM
How to implement a property like ControlToValidate property? Jeff ASP .Net Web Controls 6 05-02-2005 01:49 PM
How to implement Web Popup windows using User Interface Process Application Block Marco Vasquez ASP .Net 0 12-30-2003 02:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57