Showing posts with label record. Show all posts
Showing posts with label record. Show all posts

Thursday, March 29, 2012

Pop Up/Refresh Issue

I have a parent page that contains a datagrid. On this page is a link to "Add New" record. I have done this by opening a child/pop up so they can enter the data in a new window. When the user submits, the parent page reloads and refreshes the data. Here is the code in the child page:

btnAdd.Attributes.Add("onclick", "window.opener.location.reload();");

I kinda have two problems here, one I can live with...for now.

Problem 1: When the page reloads, the user has to click "Retry". This works, but is a bit sloppy. I've searched a few different methods on this forum, but none seem to submit and refresh my data. (I can't simply refresh because I have a few panels on the parent that throw a wrench into it)

Problem 2: The line that I posted earlier is fine, and works well; however I do have some validation (server side) on the child form. If the validation in the btnAdd_Click event isn't a success, I would like to avoid reloading the parent. How would I go about doing that?

Thanks.

Just to clarify a bit, I want to check a condition before I have my js reload the parent page.

Let's say:

If (someCondition)

{

//reload parent page

}

else

{

// don't reload parent page

}

Any suggestions?


Instead of spamming the forum with much of the same problem, I'll add to this one.

I would also like to somehow clear the last submmited button on the parent from the child. Let me try to explain.

On the parent the user may press a button which kicks off validation on the server. If validation on the server fails, a message on the page is displayed. (Parent) Now, if the user decides to add a record at this time via the pop up or child, hitting update on the child will reload the parent page; however, in this case my grid on the parent won't refresh because it's executing the submit on the parent. Therefore displaying "validation failed", when in fact it didn't.

Eh, I know this probably sounds messy, but if someone can help with this or any of my other pop up/refresh problems in this thread, I would appreciate it.


I don't know of this is going to help you or not but here is my 2cents. On the child pop up page when the user submits the informationyou can send a value of true to the parent which will represent thatthe child form has been submitted. This value can be send usingQueryString or Session State. When the parent page recieves thisinformation it can referesh it.
Does that help ?

Friday, March 16, 2012

Populating Dropdown List

Hi all,

I am not able to select any value from my dropdownlist,it always returns the first value. Based on the selection the corresponding record should be displayed in a text box. I have given my code here. I am totally frustrated. Pls check it out.

Page_load event
If Not Page.IsPostBack Then
sql = "select scode from supplier"
cmd = New SqlCommand(sql, con)
read = cmd.ExecuteReader
While (read.Read)
ddlscode.Items.Add(read.Item(0))
End While
ddlscode.DataBind()
End If

Private Sub ddlscode_SelectedIndexChanged(...)...
Dim sql As String
Dim i As Integer
Dim tempscode As String
con.Open()
sql = "select * from supplier "
cmd = New SqlCommand(sql, con)
adap = New SqlDataAdapter(cmd)
dt = New DataTable()
adap.Fill(dt)
For i = 0 To dt.Rows.Count - 1
If dt.Rows(i).Item("scode") = ddlscode.SelectedItem.Value Then
txtsaddr.Text = dt.Rows(i).Item("saddr")
End If
Next
read.Read()
read.Close()
con.Close()
End Subtry setting the View state of the control to true.

Set AutoPostback property equal to true.and write this code in page load

if(!page.IsPostback)

{

SqlDataReader rr;

rr=Com.ExecuteReader();

DropDownList1.DataSource=rr;

DropDownList1.DataBind();

}

Select the Value Selected value of DropdownList as

DropDownList1.SelectedItem.Text

I hope this will work but this is in c# convert into Vb


Not sure what's causing you problem, but it might be linked to your loop in the second function. A better way of handling it might be:

Private Sub ddlscode_SelectedIndexChanged(...)...
Dim sql As String
con.Open()
sql = "select saddr from supplier where scode = '" & ddlscode.SelectedItem.Value & "'"
Dim sqlComm As new System.Data.SqlClient.SqlCommand(sql,con);
txtsaddr.Text = sqlComm.ExecuteScalar()
con.Close()
End Sub

The SQL should only return 1 row (I've assumed the selected code is a text value) and the ExecuteScalar call returns the first column (in this case the 'saddr')

Hope this helps,
Nic