0
votes

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

2
Please refer to this How to ask. - SᴇM
I don't understand the question. The pictures confuse me more than anything. - mjwills
Provide minimal reproducible example code to explain your issue - without code it's hard to find solution from this question. - Tetsuya Yamamoto
Please find the answer here I have resolved it by myself. - bizimunda

2 Answers

1
votes

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;
0
votes

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"];