locked
Embed an on click Server side event in the dll RRS feed

  • Question

  • User-140528697 posted

    Hi,

    I am creating a custom control and have a few HTML control rendering includes a button i want to embed an OnClick(Server side) event into the dll .Please suggest me something..!!

    Thanks n Regards,

    Francis P.         

    Monday, May 5, 2008 12:50 AM

Answers

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    all the values entered in those textboxes but now i want to access those values on the server side

    <o:p> </o:p>

    When you get the value from html control in javascript, and save them in the hidden field, do you forget to assign the runat=’server’ attribute. Only the server control can be accessed in code behind.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 10:21 PM

All replies

  • User-1363023537 posted

    on initialization

    EnsureClidControl();
    Button1.Click += new EventHandler(Button1_Click);

    Then write below method that you want to execute on button click

     void Button1_Click(object sender, EventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }

    Satalaj

    Monday, May 5, 2008 5:51 AM
  • User-140528697 posted

    Thanks Satalajbut isn't this for adding controls dynamically?I m creating a custom control which contains 3 input type='text' boxes and one button no ASP.Net controls at all now is it possible for me to create my own custom event for this HTML button i render..!!!And also how do i acess the values in those 3 textboxes
    at server side that is in my dll..!!

    Thanks n Regards,

    Francis P.
     

    Monday, May 5, 2008 6:06 AM
  • User-1363023537 posted

     void Button1_Click(object sender, EventArgs e)
        {
          EnsureChildControl();
          string x =     txtFirstName.text;
          string y = txtLastName.text;
        }

    Monday, May 5, 2008 6:31 AM
  • User-140528697 posted

     Hi thanks for ur reply..!! Well but im not adding controls dynamically i override the render method and render a table with 3 textboxes these text boxes are not asp:Textbox controls these are the HTML <input type='text' control i render that.I cant use that i tried with using a hidden field that is onclientclick or so but the hidden field i try to access from the server side code with RegisterScriptStartUp,RegisterScriptBlock,RegisterScriptOnSubmit none of them seem to work..!!!

    Thanks n Regards,

    Francis P. 

     

     

     

    Monday, May 5, 2008 8:32 AM
  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to fire an javascript event from an html control in your custom server control, right?

    <o:p> </o:p>

    If so, you can follow the steps below:

    <o:p> </o:p>

    1, Write your javascript functions in a js file. And embedded the js file into your custom server control project. (So in this way the js file can be embedded into the custom server control dll).

    <o:p> </o:p>

    2, Try to include the js file, you can get the resource url of the js file by using GetWebResourceUrl method.

    <o:p> </o:p>

    3, use htmlwriter to render your html control. (including the onclick=’myfunc()’)

    <o:p> </o:p>

    Thanks.

     

    Monday, May 5, 2008 11:30 PM
  • User-140528697 posted

     Hi, Actually I have done that all im able to call the javascript function in tht javascript function i get all the values entered in those textboxes but now i want to access those values on the server side thts within the component i have a hidden field which sets all the values to the hidden field now i have the hidden field being rendered on the Render method so everytime there is a post back i lose the values..!Is there any way as in i can access values entered in those text boxes on the server side..!!

    Regards

    Francis P.     

    Monday, May 5, 2008 11:54 PM
  • User-1363023537 posted

    try Request.Parms["fieldid or name"] // it can take the value posted by both get and Post method

    Satalaj

    Tuesday, May 6, 2008 12:26 AM
  • User-16411453 posted

     There are a few tutorials on how to create Custom Server Controls on the web, and hundreds of code examples in this forum, 'Custom Server Controls', that illustrate the makeup and requirements to compile your custom control successfully, and make it work in both design and run time modes. A simple control like the one you described; should not take you more that 3 days to write and test.

    Good Luck with your first control project!

     

     

    Tuesday, May 6, 2008 7:18 PM
  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    all the values entered in those textboxes but now i want to access those values on the server side

    <o:p> </o:p>

    When you get the value from html control in javascript, and save them in the hidden field, do you forget to assign the runat=’server’ attribute. Only the server control can be accessed in code behind.

    <o:p> </o:p>

    Thanks.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 6, 2008 10:21 PM