0

I'm new to this world. Let me explain you by photos.enter image description here

Here is the first photo, I have a user control called "Adress.ascx" and on this page there are 2 different types of controls.

  1. Asp.net controls (red)

  2. Html controls (green)

This user control, I have implemented on another page called Index.aspx

enter image description here

What I want to do is, whenever I click on the button "Copy button", whatever is in the html controls copy to User control.

On Html controls, I'm using Google Maps API to search addresses.

Even, if I don't implement my user control to another page, I'm not able to copy html controls value to asp.net user controls.

For example, I have one asp:TextBox called tbStreet on user control and one Html textbox whose ID is id=street_name. I want to copy street_name's value to tbStreet.

Asp.net control code

 <asp:TextBox ID="tbStreet" runat="server" MaxLength="50" 
 CssClass="inputfield M"></asp:TextBox></td>

Html control code

<input class="field" id="street_name" name="streetName"
            disabled="true"></input></td>

Button code

protected void btnCopy_Click(object sender, EventArgs e)
    {

        string street = Request.Form["street_name"];

    }

But I don't get any value in variable street

4
  • Please refer to this How to ask. Commented Oct 27, 2017 at 8:37
  • I don't understand the question. The pictures confuse me more than anything. Commented Oct 27, 2017 at 8:41
  • Provide minimal reproducible example code to explain your issue - without code it's hard to find solution from this question. Commented Oct 27, 2017 at 8:42
  • Please find the answer here I have resolved it by myself. Commented Oct 31, 2017 at 8:25

2 Answers 2

1

If you have the HTML input like this:

<input class="field" id="street_name" name="streetName" />

You should set the name attribute value as Request.Form argument instead of id:

protected void btnCopy_Click(object sender, EventArgs e)
{
    string street = Request.Form["streetName"].ToString();
}

Note that disabled attribute prevents value to be submitted in postback, I recommend to remove that attribute and replace it with readonly if you just want to disallow users editing its value:

<input class="field" id="street_name" name="streetName" readonly="readonly" />

If the text box belongs to a usercontrol, you can create a property to get the text value from it, assumed the input element has runat="server" attribute:

public string StreetName
{
    get { return street_name.Text; }
}

Then you can access usercontrol object properties with this:

UserControl control = (UserControl)Page.FindControl("UserControlId");
string street = control.StreetName;
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried to make a property but no luck. I thinks its a User control and maybe something extra we need to do. If I just create a normal aspx page there I can retrieve the values but from User control I have no idea what is missing.
0

See the docs - https://msdn.microsoft.com/en-us/library/ms525985(v=vs.90).aspx

The element is referenced by name rather than ID, so:

string street = Request.Form["streetName"];

3 Comments

thank you very much, I have tried even with ID but not luck.
Yes your code shows that you're using ID, have you tried with Name?
yes I have tried with Name. Maybe I have to cast like (Adres)Request.Form["streetName"];? because it is on a UserControl page?

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.