1

I know I'm asking 2 questions but I'm really stuck. I have a form for adding and updating records and when I click the Update button(my Add works fine with the pop-up), I want a pop-up to appear with the properties of the record I get from my script(i.e. every texbox/dropdownlist filled with the correct values).

This is my script:

function btnEditEP_Click() {
            var recID = document.getElementById('<%=tboxEdit.ClientID%>').textContent;
            //if (recID !=null) {
            //    alert("ok what now?");
            //}
            window.open("editPopupEP.aspx?Txt=" + recID, "_blank", "toolbar=yes", "resizable=yes", "scrollbars=yes");
        }

And this is my PageLoad in editPopupEp.aspx.cs

protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int recID = Convert.ToInt32(Request.QueryString["Txt="]);
                ...
                ..
                .

If I can get the record ID, populating the input fields is easy but I need/want to get the Text of the Textbox and receive it from codebehind with QueryString.

The pop-up window works and there are no errors but the recID has 0 in it and there is no such record.

2 Answers 2

1

In the below line you are using textContent, it is not available in IE8 or below. Are you by any chance working on IE8?

var recID = document.getElementById('<%=tboxEdit.ClientID%>').textContent;

You can try something like this otherwise:

var recID =  document.getElementById('<%=tboxEdit.ClientID%>').value;

In your page_load event, you can use the below code:

int recID = Convert.ToInt32(Request.QueryString["Txt"]);

Use above code if textbox will always have integer value otherwise use below code.

int recID;
if(Int32.TryParse(Request.QueryString["Txt"], out recID))
{
 //Do whatever you want to do with recID
}
Sign up to request clarification or add additional context in comments.

Comments

1

You have to omit the equal sign when accessing the QueryString collection, like this:

Request.QueryString["Txt"]

6 Comments

I get this error when I do that {"Input string was not in a correct format."}
This probably means that the conversion with Convert.ToInt32 failed because the input is not a valid string (probably because it's null). This would mean that there is no "Txt" QueryString present. Have you tried to set a breakpoint and check the contents of Request.QueryString?
It appears to be {Txt=}. I removed the equal sign from Request.QueryString though.
I think this means that the query parameter Txt is present, but without value. If it would have a value, it would look like this: {Txt=1234} So this makes me believe you are not setting the Txt query param in your JS correctly. What's the value of recID?
Also, you could always try to manually open the editPopupEP.aspx page and pass it a hard-coded record ID. This would help you figure out if you have a problem in your JS or in your code-behind.
|

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.