-1

The front end of this code has already been developed, and uses jquery in multiple places to intercept the user's click. Here I have a radio button that, when clicked, fires the event below. I need to make this even fire for the html input element from my code behind on the page load event to pre-fill the radio buttons. How can I do this?

Jquery event to fire:

    //checkboxes
    $('.questions-form a.toggle').bind('click', function (event) {
           //jquery magic
     }

html elements that I need to select, or click:

                            <div id="form-error" style="display: none"></div>

                            <div class="questions-form" id="shipping-questions-form">

                                <div class="question question-textarea has-subquestions">
                                    <div class="question-intro clearfix">
                                        <h2>Did You Receive The Product As Ordered?</h2>

                                        <div class="no-yes answer-acceptable">
                                            <div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
                                            <a href="#" class="toggle"></a>
                                            <div class="yes"><label class="label-2" for="shipping_question_ID_product_received_as_ordered_acceptable">Acceptable</label></div>
                                            <label class="universal-label"></label>

                                            <input type="radio" id="shipping_question_ID_product_received_as_ordered_not_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Not Acceptable" runat="server">
                                            <input type="radio" id="shipping_question_ID_product_received_as_ordered_acceptable" name="shipping-question-ID-product-received-as-ordered" value="Acceptable" checked="true" runat="server">

                                        </div>
                                    </div>
1
  • 2
    While it's totally possible, it's likely a poor design if you need to do this. Perhaps you should separate out what needs server side interaction from what doesn't? Commented Sep 23, 2014 at 16:43

2 Answers 2

1

You can use

ScriptManager.RegisterStartupScript Method (Page, Type, String, String, Boolean);

where the parameters are

**page**
Type: System.Web.UI.Page
The page object that is registering the client script block.
**type**
Type: System.Type
The type of the client script block. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
**key**
Type: System.String
A unique identifier for the script block.
**script**
Type: System.String
The script to register.
**addScriptTags**
Type: System.Boolean
true to enclose the script block with <script> and </script> tags; otherwise, false.

Example to use see :how to call jquery function call in asp.net c#?

Sign up to request clarification or add additional context in comments.

3 Comments

In the code above, I have multiple inputs that have the same click event. How can I call this function for a specific radio input, say "shipping-question-ID-product-received-as-ordered"?
place it inside protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { }
I am a bit confused...I need to send the click event "shipping-question-ID-product-received-as-ordered", can I still do this using the method described in your answer?
0

The following code performed the needed functionality. I invoked this function by "clicking" the anchor attached to the object.

<div class="no"><label class="label-1" for="shipping_question_ID_product_received_as_ordered_not_acceptable">Not Acceptable</label></div>
<a href="#" class="toggle" runat="server" id="shipping_question_ID_product_received_as_ordered_link"></a>

Then in the code behind:

var autoRunScript = string.Format("<script>$(function() {{ $('#{0}').click(); }} );</script>", shipping_question_ID_product_received_as_ordered_link.ClientID);
Page.RegisterClientScriptBlock("keyClientBlock", autoRunScript);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.