Showing posts with label item. Show all posts
Showing posts with label item. Show all posts

Thursday, March 29, 2012

Pop Ups

Hi

I am using a popup, I launch the popup from a form, the user then choses an item on the popup, which is put into a session variable and then another form is launched. This works OK except the original form which launched the popup is still open how do I close it when the popup is launch. I use the code below to launch the popup

Dim sTempAsString

sTemp = "<script>window.open('LPopUpContractor.aspx',null,'top=150,left=250,height=150,width=450,status=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=no');</script>"

Response.Write(sTemp)

Response.Flush()

Thanks

Louisa

Hi,
you can close the form from its container window,
<!-- Put this script in MyMainForm.aspx -->
<script type="text/javascript">
window.open('myPopupForm.aspx');
window.close();
</script>

or let the popup close the window that launched it,
<!-- Put this script in myPopupForm.aspx -->
<script type="text/javascript">
if(window.opener) {
window.opener.close();
}
</script>

This works brillantly, but I now get a popup before mine saying:

The Web page you are viewing is trying to close the window

Do you want to close this window?

I click on the yes and my popup appears, how do I get rid of the error msg popup?

Thanks

Louisa


Hi,
it is not an error message popup, it is an Internet Explorer security setting that prevents a script to close a window that wasn't opened by the script itself, without the user permission... well, it seems that a workaround exists for Internet Explorer, just try to set the window.opener property to some value. For example
<script type="text/javascript">
window.opener = this;
window.open('myPopup.aspx');
window.close();
</script>

but I'm not sure it will work on all browsers.


Hi,

The above doesn't seem to work for me as it just puts the pages into a loop, can I not close a previous page from the page load of the new page, when the new page is fully loaded?

Thanks

Louisa


Hi,
I don't know if a workaround exists for the security popup. Try to post this question in theClient Side Web Develoment section of these forums.

a little discussion about that same pop-up

http://forums.asp.net/962609/ShowPost.aspx


Hi,
thanks for posting the link, onewisehobbit.

Saturday, March 24, 2012

Populate Dropdownlist with arraylist

I thought that by using the follwing code that the dropdown value wouldbe the second item mentioned in my list item but it seems to be thefirst that get in the selectedTex as well as the selectedValuefield. Is there something that I am missing so that theselectedValue would be the second item of my listeItem?
Thank you
<code>
'********************************************************************************
'********************************************************************************
Private Sub insertTables()
'********************************************************************************
Dim lstColums As New ArrayList
lstColums.Add(New ListItem("Software", "Cl_Systems.Software"))
lstColums.Add(New ListItem("SystemType", "Cl_Systems.Software"))
lstColums.Add(New ListItem("SystemPurchaseDate", "Cl_Systems.SystemPurchaseDate"))
lstColums.Add(New ListItem("ServicePlan", "Cl_Systems.ServicePlan"))
lstColums.Add(New ListItem("ServicePlan_Purchase", "Cl_Systems.ServicePlan"))
lstColums.Add(New ListItem("ServicePlan_WarrentyEnd", "Cl_Systems.WarrentyEnd"))
lstColums.Add(New ListItem("ServicePlan_RenewalDate", "Cl_Systems.RenewalDate"))
lstColums.Add(New ListItem("BuiltID", "Cl_Systems.BuiltID"))
lstColums.Add(New ListItem("Software Version", "Cl_Systems.Version"))
lstColums.Add(New ListItem("Modules", "Cl_Systems.Modules"))
lstColums.Add(New ListItem("Packages", "Cl_Systems.Packages"))
lstColums.Insert(0, "--Select Field--")
ddFields.DataSource = lstColums
ddFields.DataBind()
End Sub
</code>
You added this "lstColums.Insert(0, "--Select Field--")" at the first posion which is "0" and you didn't set your selectedvalue when the DDL loaded, so the default selectedvalue is the first one.

Event if I take that line away it give me the same result.


Are you really creating the list like this? If so, I suggest either (a) creating a ListItemCollection instead, or (b) skipping the intermediate object altogether and just adding the items to the dropdownlist's Items collection.

Populate textbox from item selected in a drop down list

I am a newbie to .net so bear with me here.

I have a page that has a dropdown list of customers. I want to select a customer from that dropdown and populate the appropriate textboxes.

So when I select 'John Smith' from the dropdown list I have a form with textboxes for first name, last name, accout id, etc that needs to populate accordingly. I am using VB.net with MS SQL. I have been successful populating the dropdown list from the DB. Where I am lost is populating the appropriate textboxes for the customer selected in the dropdown list. Any help is appreciated.Hi,

If you are having the dropdownlist and the textbox in the same form, then you need to do as below:-

Set the autopostback property for the dropdownlist to true. This will make the dropdownlist post back to the server, once an element is selected. Then, you can put the following code in your codebehind file to get the selected item.

If Not IsPostBack Then

textbox1.text = dropdownlist1.SelectedItem.Text

End If

If you are having the textbox in a different form, then you need to pass the selected value by querystring to that form.

If Not IsPostBack Then

Response.Redirect("NewForm.aspx?name=" & dropdownlist1.SelectedItem.Text)

End If

Then in the new form, you can get the value using the following code:-

textbox1.text = Request.Params("name")

Hope it helps.
Something to keep in mind:

The name of the user (or whatever) may not be unique. You can have two people with the name "John Smith." You propably have a column in your DB that is unique for each person like UserID or whatever.

So when you update the dropdownlist from the database, you need to retrieve the unique id for each person as well, so that when the index of the selected index in the drop down list changes, you can use the corresponding unique ID to retrieve the other info from the database.

I cant remember exactly, but you should take a loot at the dropdown control itself. Many such controls have a 'Value' for each item in them. You van set the 'Value' to the unique ID somehow.

Youll have to take a look...

Wednesday, March 21, 2012

Populate textbox with dropdown selection (in Wizard Control), using javascript

I have a Wizard Control that contains a number of controls:

After the user selects an item from a DropDown, and the control has lostfocus, I need the selected value to pre-populate a TextBox usingjavascript.

If I create a 'new website' and just throw a dropdown list and textbox onto the page the following code works perfectly:

** Default.aspx.vb:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.Attributes.Add("onblur", "FillTextbox()")
End Sub

** Default.aspx:

function FillTextbox ()
{
document.getElementById("TextBox1").value=document.getElementById("DropDownList1").value;
}

The above code, however DOESN'T work if the controls are embedded in a wizard control.

Thus, my question is: How do I get the code to work if the DropDown and TextBox controls are in a Wizard Control?

Any help would be much appreciated!

I believe when the control is embedded within another control the actual name that ends up being used includes the parent-control's name, e.g. Parent_mycontrol. Take a look at the source (right click, View Source) when you run the page to find the actual name of the control. You can reference it by that name in your javascript, fillTextbox() function.

Good luck.


You need to find the correct ID for the TextBox control. As suggested by the fellow developer you need to use the View Source and find the correct ID for the TextBox control. Once, you find the correct ID simply use that Id in the javascript function.

Thank you both SO MUCH for your help! That worked like a charm!Big Smile

Friday, March 16, 2012

Populating drop down list from database AND manually

I have a drop down list which ive popukated from my SQL Server database. However, I want to manually add another item to the list, as it doesnt appear in my DB query.

How do I do this ??

thanks
ferkh10You can use the "insert()" methods of the item array in the drop down list.

If you want to place it after all your values, just do "Insert()".

example:

dropdown.Items.Insert(new ListItem("Text", "value"))

If you want to place it in a particular place, do

dropdown.Items.Insert(IndexToPutItem, new ListItem("Text", "value"))

Note that code is in C#

Hope this helps,
Covo
ddl.Items.Insert(0,New ListItem("text","value"))
My DDL is created in an EditItemTemplate, and I dont seem to be able to reference it from my code behind. Heres where i created the DDL :


<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlAccountNames" DataValueField="intMTIID" DataTextField="vchAccount" DataSource='<%# GetAccountNames() %>' SelectedIndex='<%# GetSelectedIndex(Container.DataItem("intMTIID")) %>' >
</asp:DropDownList>
</EditItemTemplate>

I populate the DDL using the code below :


Function GetAccountNames() As DataSet
'Populate the ddlDataSet

Const strConnStr As String = "XXXXXXXXXXXX"
Dim myConnection As New Data.SqlClient.SqlConnection(strConnStr)

Const strSQL = "spGetMarketTraderAccounts "
Dim myDataAdapter As Data.SqlClient.SqlDataAdapter = New Data.SqlClient.SqlDataAdapter(strSQL, myConnection)
myDataAdapter.Fill(ddlDataSet, "Accounts")

Return ddlDataSet
End Function

Whereabouts do I need to put the InsertAt statement ? Ive tried putting it into the GetAccountNames function, but its not recognising the DDL name.
If it is in edit item you can reference it in codebehind from DataGrid's ItemDataBound event handler (you get the correct item by checking when item is of type EditItem, from event handler's event arguments)
Im still having real problems with this. Can anybody post a code example that I can use ??

thanks.
Your grid could be like this:


<asp:DataGrid ID="ExampleGrid" Runat="server" AutoGenerateColumns="False">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" EditText="Edit" CancelText="Cancel" />
<asp:TemplateColumn>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"SelectedField")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList runat="server" id="ddlAccountNames" />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="SomeText" ReadOnly="True" />
</Columns>
</asp:DataGrid>

Then the code:


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Bind DataGrid to dummy data
Bindgrid()
End If
End Sub

'Bind the grid itself using dummy data
Private Sub Bindgrid()
Dim dt As New DataTable
dt.Columns.Add("SelectedField", GetType(Integer))
dt.Columns.Add("SomeText", GetType(String))

Dim dr As DataRow = dt.NewRow()
dr(0) = 1
dr(1) = "One thing here"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 2
dr(1) = "Two things there"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 3
dr(1) = "Three things anywhere"
dt.Rows.Add(dr)

ExampleGrid.DataSource = dt
ExampleGrid.DataBind()
End Sub

Private Sub ExampleGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles ExampleGrid.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
'LOcate the DDL in the edit item
Dim ddl As DropDownList = CType(e.Item.FindControl("ddlAccountNames"), DropDownList)
ddl.DataSource = GetAccountNames()
ddl.DataValueField = "Field"
ddl.DataTextField = "Text"
ddl.DataBind()

'Search for the item in grid's data source and put it as seleted
Dim ditem As DataRowView = CType(e.Item.DataItem, DataRowView)
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(ditem("SelectedField")))
End If
End Sub

Private Function GetAccountNames() As DataSet
'Using dummy data here for ddl populating
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("Field", GetType(Integer))
dt.Columns.Add("Text", GetType(String))

Dim dr As DataRow = dt.NewRow()
dr(0) = 1
dr(1) = "One"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 2
dr(1) = "Two"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 3
dr(1) = "Three"
dt.Rows.Add(dr)

Return ds
End Function

Private Sub ExampleGrid_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ExampleGrid.EditCommand
ExampleGrid.EditItemIndex = e.Item.ItemIndex
Bindgrid()
End Sub

Private Sub ExampleGrid_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ExampleGrid.CancelCommand
ExampleGrid.EditItemIndex = -1
Bindgrid()
End Sub

This example doesn't show how to pass changes in DDL to the database, but that shouldn't be big deal either.