|
I've didn't work with ajax method How can I call it to push to the server?
this is my code:
<asp:content id="Content1" contentplaceholderid="head" runat="Server">
var MENU = [];
MENU[0] = [];
MENU[1] = [];
MENU[0][0] = new Option("New York", "NY");
MENU[0][1] = new Option("New York City", "NYC");
MENU[0][2] = new Option("Syracuse", "SYR");
MENU[1][0] = new Option("California", "CA");
MENU[1][1] = new Option("Los Angeles", "LAN");
MENU[1][2] = new Option("San Diego", "SDI");
function populateMain(mainSel, subSel) {
var mainMenu = mainSel;
var subMenu = subSel;
mainMenu.options.length = 0;
for (var i = 0; i < MENU.length; i++) {
mainMenu.options[i] = MENU[i][0];
}
populateSub(mainMenu, subMenu);
}
function populateSub(mainSel, subSel) {
var mainMenu = mainSel;
var subMenu = subSel;
var optMainMenu;
subMenu.options.length = 1;
optMainMenu = mainMenu.selectedIndex;
for (var i = 1; i < MENU[optMainMenu].length; i++) {
subMenu.options[i] = MENU[optMainMenu][i];
}
}
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="Server">
--Please Choose--
////////////On server side
protected void Page_Load(object sender, EventArgs e)
{
const string someScript = "alertMe";
if (!ClientScript.IsStartupScriptRegistered(this.GetType(), someScript))
{
ClientScript.RegisterStartupScript(this.GetType(),
someScript, "populateMain(document.getElementById('State'), document.getElementById('City'));", true);
}
}
I can't get the value of menu in server side!I wan't to save them in database so what's your sugestion?
|
|
|
|
|
Now we can see what you are doing. Of course you can't get the value in the code behind because you are setting the values on the client side, the server knows nothing about this. You would be better off binding the combobox to a data source, it doesn't have to be a data table or dataset, any collection will do.
What you appear to be attempting to do is called a cascading drop down and there are multiple sources available if you look.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
But how can I bind this combobox to a data source!!? Do you see my code? my combobox isn't a component
|
|
|
|
|
Then make it so! Why are you making this more difficult on yourself?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Because my combobox is not a server control, it's a html control so how can I bind data source to html control?!please guide me.
|
|
|
|
|
Once again. Why must it be an html control? Why are you making it difficult on yourself, and us, by not using ASP.NET controls in an ASP.NET application?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Because I want to do this in client side Not in server side client side is faster than server side Do you have any suggestion or not?
|
|
|
|
|
Elham M wrote: client side is faster than server side
Not necessarily. There are many factors to consider.
By hard coding values into the JavaScript you have reduced the maintainability and extensibility of the code and application making it more difficult on yourself and those that may follow. Knowing the proper tools and when to use them is the mark of a real developer not just a hobbyist or hacker. Which are you?
You can easily get the values using JQuery
var menuVal = $("#menu").val();
var subMenuVal = $("#submenu").val();
One way of passing them to a server method
Code-behind
[WebMethod]
public static void Foo(string menu, string subMenu)
{
...
}
JavaScript
PageMethods.Foo( menuVal, subMenuVal);
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I hope this will help u, if not ask if u need further clarification (there is code here!).
Otherwise use ajax to send you newely populated data back to the server.
|
|
|
|
|
I think ajax is good suggestion But where is your code?!
|
|
|
|
|
Try this:
1. Default.aspx
<select id="sel1"><option>came here first!</option></select>
<select id="sel2"><option>came here second!</option></select>
<input id="send" type="button" value="Send Date" />
<asp:ScriptManager ID="test" runat="server">
<Services>
<asp:ServiceReference Path="test.asmx" />
</Services>
</asp:ScriptManager>
2. Your JS/SQuery
<script type="javascript/text">
$(function(){
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
$('#send').click(function(){
$sel1_value = $('#sel1').val();
$sel2_value = $('#sel2').val();
test.SendData($sel1_value, $sel2_value, SendSuccess, SendFailed);
});
function SendSuccess(result, eventArgs)
{
alert(result);
}
function SendFailed(error)
{
alert(error);
}
});
</script>
3. Webservice (test.asmx)
- Create a new webservice called test.asmx
- Create a new [WebMethod] called SendData in this class like so:
[WebMethod]
public string SendDate(string sel1, string sel2)
{
return "...holla! i got here last!!!";
}
Oops!!! don't forget to download and reference the latest JQuery Library in your project!
Goodluck
|
|
|
|
|
Who were you responding to?
MorgSim wrote: I hope this will help u
Hope what helps?
MorgSim wrote: use ajax to send you newely populated data back to the server.
Brilliant! Exactly what I have suggested days ago.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: Hope what helps?
Your suggestion
|
|
|
|
|
|
Your query is not clear still....
Keep autopostback property of your combo box true and on SelectIndexChanged() event of ComboBox you can take the value Selected by user.
|
|
|
|
|
And where did the OP mention anything about a combobox?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I asked something like this last week but haven't gotten an answer just yet, so I thought I would ask it again in a different way. I am working on a site for our hr department to take online applications. Part of the process is allowing users to upload their resume for a job posting instead of filling out the entire application. Originally I had planned on having the resumes upload to a folder on the web server, but since we will be running a background job on the sql server to delete applicant data older than 60 days after a job posting has ended, I thought it might be better to just put the resumes into the database. What is the best practice on storing and retrieving documents in sql server using asp.net?
|
|
|
|
|
Check this[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
|
Hi All, I need to catch an event when user select an item from ListBox. I am not sure if I have to use Javascript. if yes how do I do it.
Please halp.
Thansk,
|
|
|
|
|
Hi jashimu,
Some "selectedindexchanged" event should be there you can use it.
just double click on list box you will get that event automatically.
Regards,
|
|
|
|
|
I get it it is true but when I select an item from the listBox it does not fire any even. I am not setting autopostback to true for reason.
thanks for your reply.
|
|
|
|
|
then you have to do that with javascript I think.
Only autopostback can solve your problem
|
|
|
|
|
I believe you are correct, either autopostback or Javascript
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|
|