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

Discussion in 'ASP .Net' started by Harvey Triana, Apr 23, 2007.

  1. 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 />
     
    Harvey Triana, Apr 23, 2007
    #1
    1. Advertising

  2. Harvey Triana

    Ray Costanzo Guest

    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%').value);
    }
    </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 />
    >
     
    Ray Costanzo, Apr 23, 2007
    #2
    1. Advertising

  3. Harvey Triana

    bruce barker Guest

    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 />
    >
    >
     
    bruce barker, Apr 23, 2007
    #3
  4. > 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 />
     
    Harvey Triana, Apr 23, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zb
    Replies:
    2
    Views:
    445
  2. Andy B
    Replies:
    1
    Views:
    1,006
    bruce barker
    Nov 15, 2008
  3. Jeff
    Replies:
    6
    Views:
    251
    KMILO
    May 2, 2005
  4. Warped
    Replies:
    2
    Views:
    530
    Warped
    Jul 15, 2005
  5. Replies:
    0
    Views:
    234
Loading...

Share This Page