|
One way would be to use a hidden field, which get's posted back to the parent.
Set the value of the hidden field to whatever you want, maybe a comma delimited list of selections from the list box.
In aspx:
<asp:hiddenfield id="thehiddenfield" runat="server" />
<script type="text/javascript">
function setHiddenField(val)
{
var el = document.getElementById(_hiddenFieldId);
el.value = val;
}
</script>
Somewhere in your Page_Load handler:
Page.ClientScript.RegisterClientScriptBlock(typeof(theform), "hiddenvar", "var _hiddenFieldId='" & thehiddenfield.ClientID & "';", true);
Note: You could just use view page source to find out the id of the hidden input field to set, if you don't want to go through all the hoops, but if it's in a control or master page and get's moved, you'll have to update the id.
Now, when your page posts back, the hidden field will be set to whatever you set it to and you can access it in the code behind using something like:
string vals = thehiddenfield.Value.ToString();
Hope that makes sense, it's kind of convoluted (but then again, so is asp.net ).
|
|
|
|
|
Hi, thanks for the reply ! It was really helpful. I have managed to implement the hidden field solution partially in a sense.
Actually I have the javascript on the insert page of the child window (popup) which sets the return value on the parent (I'm using only 1 value of a textbox atm)
Now I have to loop through the values of the asp.net control listbox but through javascript and then insert them on the parent page.
Like on the popup page,
the user selects multiple items thorugh a grid which gets added to a listbox and then on the insert button I have to return all the values added on the listbox to the parent page text box.
Any help in this regard is appreciated.
Thanks !
Code, Code, Code, chill lol.
|
|
|
|
|
Great, glad you got it sort of working
To get the selected values from your multi-select list box your can iterate through the options of the select element:
var lb = document.getElementById("yourlistbox");
var selections = "";
for (var i = 0; i < lb.options.length; i++)
if (lb.options[ i ].selected)
if (selections.length > 0)
selections += "|";
selections += lb.options[i].value;
This creates an pipe "|" delimited string of selected values. Not sure how you're going to pass them back to the parent, maybe in the url as a parameter:
self.opener.location = "parentpage.aspx?selections=" + escape(selections);
Then in your parent page you can look at Request["selections"] and parse them.
Hope that helps!
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
hooray ! thanks so much for the reply !
I managed to get your code working . Its returning the values as well but I'm having a problem in setting the values to the textbox on the parent page.I am trying to set it via window.opener method. But its always displaying the last value on the list box
here is part of my code for reference.
for(var i=0;i <list.options.length;>{
alert(list.options[i].value);
window.opener.document.getElementById(Str3).value=list.options[i].value+";";
}
window.close();
Code, Code, Code, chill lol.
|
|
|
|
|
Try:
var val = "";
for(var i=0;i < list.options.length; i++) {
val += list.options[i].value+";";
}
window.opener.document.getElementById(Str3).value=val;
window.close();
- S
50 cups of coffee and you know it's on!
A post a day, keeps the white coats away!
|
|
|
|
|
its working now , thanks so much.
Greetings and best wishes from Sweden sir.
Code, Code, Code, chill lol.
|
|
|
|
|
Hello Mr. Steve,
Well I am having problems parsing and with setting the ids for the selected names from the list so now my manager has asked to transfer the (text,values) from listbox (on child page) to a list box on parent (text,values).
I tried some code but its not working. Here it is ...
function Child()
{
var Str1 = document.getElementById('txtCompCode').value;
var Str2 = document.getElementById('txtCompName').value;
var Str3 = document.etElementById('txtData').value;
var list = document.getElementById('lboxCompList');
var flist= Str3;
var osel = document.createElement("option");
var val=""
for(var i=0;i <list.options.length;>{
alert(list.options[i].value);
val += list.options[i].value+",";
}
alert(flist);
flist.options.add(osel);
osel.text=val;
osel.value=val;
window.close();
}
Code, Code, Code, chill lol.
|
|
|
|
|
hello everyone...
i have a problem..how can i reset the previous value in tab panel when i click another tab?
hope you can help me...
thanks a lot...
jyn
|
|
|
|
|
I have a asp.net page where my button is enabled or disabled depending on whether two textboxes are properly filled out. I enable/disable the button through the onchange events of the textboxes. Once button is enabled and I click it, the postback seems to have disappeared because it does nothing.
I enable/disable the button like this:
function checkBuild() {
document.getElementById('sMsg').innerHTML = '';
checkBAL();
checkINI();
if ((checkBAL()) && (checkINI())) {
document.form1.btn1.disabled = false;
checkWarning();
} else {
document.form1.btn1.disabled = true;
}
}
I've read that in order for the button "btn1" to postback, I must have it enabled onLoad which I have done for testing. Therefore, if I click the button before my javascript fires, it works; only stops working once my checkBuild() function is called by the textboxes javascript onchange event. Can anyone help with this issue? Many thanks.
modified on Monday, September 22, 2008 10:31 PM
|
|
|
|
|
Call the javascript function on the bottom of the page.
|
|
|
|
|
I have asked this question in the SQL message board but am unsure if that would be the right place.
The problem is that im using an accordion which houses a bunch of textboxes. Now I have a SQLDATASOURCE that I bind to those textboxes (which are in about 4 different panes). I can choose the textboxes from the list, I can type the textboxes in the codebehind and everything. You know when you use stuff like LoginView you have to use the FindControl.
Now when I perform the insert command it says it can't find the first one (txtDescription) and stops. So I said ok, lets put the SQLDATASOURCE i nthe same pane with txtDescription. Works! Then it can't find the first textbox in the next pane!
How would I get around this? I love the way (and everyone else that has seen it) I made it with the accordion.
|
|
|
|
|
I'm trying to create a dynamic URL in a report viewer, but I am having a tough time at it. What I need to do is have a link "View" that has a URL of http://server/path to page/View.aspx?ReportNumber=.
I need to pass the Number column's value for the navigation of the link. I can get it to the point where I can use a static URL, but not dynamic. Any pointers?
|
|
|
|
|
There are about 10 pages in my project which are used to populate reference tables and each page needs to have text boxes to input data and format (i.e. number of text boxes, format of data etc) So I want to make a user control for data entry and place in all pages so that I dont have repeat the same code. But I not very comfortable with events and delegates and also passing data to and from a user control and webpage. Can someone suggest me code or some links which help me in doing this.
Thanks
Uday
Uday
|
|
|
|
|
Any book on ASP.Net 2.0 should have examples of this.
I would also suggest that you are making things more difficult than need be. What is wrong with having 10 pages to update 10 tables? That seems like good design to me. Putting code to update 10 tables in one user control seems like a terrible idea. Why take something simple and make it complex like that?
Think about this. If you don't touch this application for a couple years and you have to modify one of these reference tables. If you have one page per table, think how easy it will be to maintain! If you have some fancy trickery to put all the code in one user control think about how much more difficult it will be to dive back into the code. Just my two cents...
I didn't get any requirements for the signature
|
|
|
|
|
No no I am not trying to put whole code to update 10 tables in same user control's code. Since the html part is same in all the pages I thought of having it in a user control and have a save button on it. When user clicks save then I thought of handling that event on the web page to save the data. Not sure if this is the right way.I am new to .Net It is really simple when I have the html part on all pages but I want have it in one place and reuse it.
Uday
|
|
|
|
|
Sorry I misunderstood. Here are some tips for you. Create a public property for any control in your user control that you want to use in the page. And vice versa. Most books will give you an example of using userControl.FindControl("id"). But I find it cleaner and easier if just create a public property.
As for events... In the page_init of the page containing the control is where you set the event. Here is a quick example...
Good luck.
<br />
public partial class WebUserControl : System.Web.UI.UserControl<br />
{<br />
public Button submitButton<br />
{<br />
get { return this.Button1; }<br />
set { this.Button1 = value; }<br />
}<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
<br />
<br />
public partial class _Default : System.Web.UI.Page <br />
{<br />
protected void Page_Init(object sender, EventArgs e)<br />
{<br />
this.WebUserControl1.submitButton.Click += new EventHandler(submitButton_Click);<br />
}<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
protected void submitButton_Click(object sender, EventArgs e)<br />
{<br />
Response.Write("event handled");<br />
}<br />
}<br />
<br />
<br />
I didn't get any requirements for the signature
|
|
|
|
|
Todd thanks for your response I could access my the controls on a user control this way. Can we also access if the user control is on a master page?
Uday
|
|
|
|
|
Yes.
I didn't get any requirements for the signature
|
|
|
|
|
|
Cache.Remove("name");
Cache.Insert("name", sh.items, null, DateTime.Now.AddMinutes(60), TimeSpan.Zero);
I didn't get any requirements for the signature
|
|
|
|
|
When I run a website project within the ID, I get the "Connection Interrupted" message. What am I doing wrong?
[EDIT] It's a two-part problem. I'm using Firefox 3 as the "browse with" setting in the IDE. Firefox is changing the host name from "localhost" to "www.localhost.com", and the VS2008 IDE is decrementing the actual port number by two before running the browser.
So, I get this:
http://www.localhost.com:49230/Default.aspx
instead of this:
http://localhost:49232/Default.aspx
I also tried it with the both the internal browser and IE7, and while the host name issue is gone, the port is STILL wrong.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Monday, September 22, 2008 12:52 PM
|
|
|
|
|
I had the same issue. Do you have Nod32 anti-virus installed? Are you using Vista? If yes, problem is with protocol filtering. If you can, stop the anitivirus program. Or you can configure Nod32, so that it won't do this.
|
|
|
|
|
hi
how can change my caption depends on my language selection
that is my default language is English so while my page is loading my caption are display in english if i m change my lang. in run mode i hav to display all captionj in selected lang.
plz shar ur ideas
with regards,
bretto
|
|
|
|
|
|
Hi all. I've got a web applicaiton here that I'm developing against IE6 (it's for a company intranet, and they're still all on IE6...) The bug I'm noticing is this - If I select any single-line text box, and enter enough text so that the length of the text exceeds the length of the text box, the textbox pushes over to the left when I tab away from the textbox, or click away from it. The funny thing is that it's not resizing or anything to display the text therein, instead it's pushing over to the left by the distance that the text exceeds its length, staying the same sixe, and the text in the textbox remains shoved over to the left in the textbox, so that the last character is visible but the first one is not. Has anybody else come across this?
|
|
|
|