IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New return false
Have a validation function on the "onClick" event for your submit button. If field is empty, alert error msg, return false. It won't actually submit the form.
--

Drew
New Tried this, but get a compile/build error
[script type="text/JavaScript"]
function CheckSearchInput()
[
	var txtBox = document.getElementById("txtResearch").value;
	if (txtBox.value == "") [
		alert("Please Enter A Value");
		return false;
	]
	return true;
]
[/script]

[ ... ]

[asp:Button runat="server" ID="btnResearch" Text="Search" CssClass="ResearchButton" OnClick="CheckSearchInput()" /]
==> gives a build error: "CheckSearchInput is not a member of 'ASP.SearchResults.aspx'. It does the same thing if I move the function into a separate Javascript file. It also gave me the build error when I made the button a standard HTML button.
"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from." -- E.L. Doctorow
Expand Edited by lincoln March 16, 2009, 04:23:11 PM EDT
New Try OnClientClick
OnClick is for sever side events.
New Really?
Man, I shouldn't be surprised that MS "extended" javascript until it doesn't work any more. Your function is fine, and the browser would do exactly the right thing with it. You just can't get the server to send it to the browser.
--

Drew
New No, Really
MS didn't "extend" Javascript. That asp:Button tag is not HTML. It's a server side ASP.Net tag that has its own attributes. Sometimes they correspond one-to-one with HTML attributes. In this case they don't.

OnClientClick tells ASP.Net to generate an OnClick attribute containing the provided Javascript code in the resulting HTML code that is sent to the client. The server side OnClick tells ASP.Net which method to call on the server when a page posts back and the hidden event form variable indicates that the button generated by that tag was clicked.

I think the root of the problem is still a misunderstanding of how ASP.Net works, specifically what happens on the server and what happens on the client and how the two communicate.

http://msdn.microsof...ary/ms178472.aspx
Expand Edited by altmann March 17, 2009, 03:28:25 PM EDT
New Re: Tried this, but get a compile/build error
Changed the Javascript function to this:
function CheckSearchInput() [
	if (document.getElementById("txtResearch").value == "") [
		alert("Please Enter A Name, A Member ID #, or A Social Security Number!");
            ]
	else [
                SearchResults.submit();
            ]
        ]
and changed the button from an "asp:button" to an HTML button. Now I'm getting the desired actions.



"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from." -- E.L. Doctorow
     2 different event responses to one Click event? - (lincoln) - (6)
         return false - (drook) - (5)
             Tried this, but get a compile/build error - (lincoln) - (4)
                 Try OnClientClick - (altmann) - (2)
                     Really? - (drook) - (1)
                         No, Really - (altmann)
                 Re: Tried this, but get a compile/build error - (lincoln)

You're right, because clearly cabbage soppy wankel ebbeh gruntsponge.
129 ms