Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:35:20+00:00 2026-05-25T06:35:20+00:00

I am trying to change the value on a hidden field in a WebBrowser

  • 0

I am trying to change the value on a hidden field in a WebBrowser control.

I can inject Javascript that displays an alert box. I can make the alert box show the current value of the hidden field. However, I cannot get the value of the hidden field to change.

I have tried changing the value by doing this (tb is the WebBrowser control):

HtmlElement head = tb.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = tb.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
element.text = "function DoIt() { document.getElementById('TestHiddenField').value='Hello World'; alert('Updated'); }";
head.AppendChild(scriptEl);
tb.Document.InvokeScript("DoIt");

In the above the alert does pop up.

And I have tried this:

tb.Document.Body.InnerHtml = tb.Document.Body.InnerHtml.Replace("MyValue", "YourValue");

In the above I see that the InnerHtml does change when debugging.

However, when the page is done loading and I view source the value is never changed.

Also, Even though I can inject javascript to and it pops up the alert, I am never able to find the javascript int the code.

What’s going on? What am I doing wrong?

Thanks!

UPDATES:

  • I’m doing this in the DocumentCompleted event.

  • I’m not using ViewState

ANOTHER UPDATE:

I added another field. This time a non-hidden text field.

<input type="hidden" id="TestHiddenField" value="MyValue" name="TestHiddenField" />
<input type="text" id="TestField" value="MyValue" name="TestField" />

Here is what happens when I do this:

tb.Document.Body.InnerHtml = tb.Document.Body.InnerHtml.Replace("MyValue", "YourValue");

When the page renders in the WebBrowser Control the text box displays the text “YourValue” but when I View Source the value still equals “MyValue”.

What’s up with that? I need for it to equal “YourValue”.

Any ideas?

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:35:20+00:00Added an answer on May 25, 2026 at 6:35 am

    However, when the page is done loading and I view source the value is never changed.

    Do not alter the DOM until after the page is done loading. You have to wait for the DocumentCompleted event to fire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to be able to change the value of a hidden field
I am trying to make a numerical value, say 5000, quickly change to another
I've been trying to set the value of a hidden field in a form
So I want to change a hidden form field's value from False to True
I'm trying to have some jquery change a hidden form value on my page
I am trying to set a hidden form field with the value of a
I am trying to control a hidden input value based on the value of
I'm trying to change the value of a dojo tree to display the correct
I am trying to programmatically change a value of a wxRadioButton in a way
I'm trying to use jQuery to change the value of button.kill . However I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.