Reputation: 467
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.
Upvotes: 1
Views: 882
Reputation: 442
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
}
Upvotes: 1
Reputation: 128
You have to omit the equal sign when accessing the QueryString collection, like this:
Request.QueryString["Txt"]
Upvotes: 1