Question

Having 2 RadioButtons and 2 TextBox on my windows form such as rdbMale and rdbFemale , txtMale ,txtFemale sililar way the same Radio Button and TextBox on my HTML page. At Html page I use some Jquery when first time dom is load I hide both the TextBoxes(txtMale,txtFemale) when I click Male Radio Button rdbMale then Textbox txtMale is show and txtFemale is hide, similar way when I click the rdbFemale then Textbox txtMale is hide and txtFemale is show.

I want to select this selection operation of Radio button from my windows form. when I click the Radio Button such as rdbMale or rdbFemale button (also In winform having 1 Button SendToHtml) when I click this SendToHtml the respective value of Radio Button is transfer to HTML page(without ant Query string etc.) and my Jquery event will handle but In my case the value radio button check value is transfer to HTML page but Jquery will not work for to show and hide the txtMale and txtFemale.

HTML Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Test Application</title>
    <script type="text/javascript" language="javascript">
        window.onload = body_Onload;
        function body_Onload() {
            document.getElementById("txtFirstName").focus();
        }

    </script>
    <script type="text/javascript" src="../App_Script/jquery-1.7.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#txtMale,#txtFemale").hide();
            $("input[name=Sex]").click(function () {
                if ($("#radMale").attr('checked')) {
                    $("#txtMale").show();
                    $("#txtFemale").hide();
                }
                else {
                    $("#txtMale").hide();
                    $("#txtFemale").show();
                }
            });
        });
    </script>
</head>
<body>
<input id="radMale" type="radio" name="Sex" value="radMale" />
    <label for="lblMale">
        Male</label>
    &nbsp;&nbsp;
    <input id="radFeMale" type="radio" name="Sex" value="radFeMale" />
    <label id="lblFeMale">
        Female</label><br />
    <input type="text" id="txtMale" /><br />
    <input type="text" id="txtFemale" /><br />
</body>
</html>

C# Class

private SHDocVw.InternetExplorer TargetIE = null;
        string url;
public Form1()
        {
            InitializeComponent();
        }
private void Form1_Load(object sender, EventArgs e)
        {
            txtMale.Visible = false;
            txtFemale.Visible = false;
        }
private void SendToHtml_Click(object sender, EventArgs e)
        {
            GetTheIEObjectFromSystem("Q_26773800");
            SendTextToActiveElementWithSubmitOptionSet(false);
        }
private void GetTheIEObjectFromSystem(string inurl = ".")
        {
            SHDocVw.ShellWindows SWs = new SHDocVw.ShellWindows();
            foreach (SHDocVw.InternetExplorer internetExplorer in SWs)
            {
                if (internetExplorer.Document is mshtml.HTMLDocument)
                {
                    url = internetExplorer.LocationURL;
                    TargetIE = internetExplorer;
                    return;
                }
            }
        }

private void SendTextToActiveElementWithSubmitOptionSet(bool btnSubmit)
        {
            mshtml.IHTMLDocument2 document = null;
            if (TargetIE != null)
            {
                document = TargetIE.Document as mshtml.IHTMLDocument2;
                if (!document.activeElement.isTextEdit)
                {
                    MessageBox.Show("Active element is not a text-input system");
                }
                else
                {
                    HTMLInputElement HTMLI;
                    HTMLI = document.activeElement as HTMLInputElement;
                    var tag = HTMLI.document as mshtml.HTMLDocumentClass;
                    mshtml.IHTMLElementCollection hTMLElementCollection = tag.getElementsByTagName("input");
foreach (mshtml.HTMLInputElement el in hTMLElementCollection)
                    {
                        switch (el.id)
                        {
                case "radMale":
                                if (radioButton1.Checked == true)
                                    el.setAttribute("checked", "checked");
                                else
                                    el.removeAttribute("checked");
                                break;
                            case "radFeMale":
                                if (radioButton2.Checked == true)
                   el.setAttribute("checked", "checked");                                       
                                else
                                    el.removeAttribute("checked");
                                break;
                        }
                    }
 }
            }
            else
            {
                MessageBox.Show("open internet explorer.");
            }
        }
private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            txtMale.Visible = true;
            txtFemale.Visible = false;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            txtFemale.Visible = true;
            txtMale.Visible = false;
        }

What I need to do while radio Button get selected from winform to Html Page and fire my Jquery event also from winform

Was it helpful?

Solution

I solve my issue I just paste the code that solve my problem instead of whole code

                           case "radMale":
                                if (radioButton1.Checked == true)
                                {
                                    el.setAttribute("checked", "checked");
                                    el.click();
                                }
                                else
                                    el.removeAttribute("checked");
                                break;
                            case "radFeMale":
                                if (radioButton2.Checked == true)
                                {
                                    el.setAttribute("checked", "checked");
                                    el.click();
                                }
                                else
                                    el.removeAttribute("checked");
                                break;

OR This way

                       case "radFeMale":
                        if (radioButton2.Checked == true)
                        {
                            elInput.setAttribute("checked", true);
                            elInput.click();
                        }
                        else
                            elInput.setAttribute("checked", false);
                        break;

                    case "txtMale":
                        elInput.value = textBox5.Text;
                        break;

                    case "txtFemale":
                        elInput.value = textBox6.Text;
                        break;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top