Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping asp.net button click event from firing

Status
Not open for further replies.

iaswnidou

Programmer
Apr 19, 2005
140
GR
Hello

I am trying to stop a postback to the server with the following scripting:

Code:
function CheckDateUpdate()
		{
var radio1 = document.getElementById('<%= rbYesDates.ClientID  %>');

var label = document.getElementById('<%= lblWarning.ClientID  %>');
			
if (radio1.checked == false)
{
 label.text = "A choice whether to update or not must be made."
 return false;
}
else
{
 label.text = ""
 return true;
}
}

And i am calling this function like this:
Code:
<asp:Button cssclass="submit" onmouseup="CheckDateUpdate()" ID="btnSubmit" Runat=server Text="Submit"></asp:Button>

But unfortunately the spotback does happen. Any ideas?
 
The function above is the Javascript function, what else is client side?
 
Server Side On Load Code

Code:
btnSubmit.Attributes.Add("onclick","return CheckDateUpdate();")

Javascript
Code:
function CheckDateUpdate(){
var radio1 = document.getElementById('<%= rbYesDates.ClientID  %>');
var label = document.getElementById('<%= lblWarning.ClientID  %>');
            
if (radio1.checked == false){
 label.text = "A choice whether to update or not must be made."
}else{
 label.text = ""
}
return false;
}


"...your mom goes to college..."
 
And where is the requested client-side HTML for this?
Code:
<asp:Button cssclass="submit" onmouseup="CheckDateUpdate()" ID="btnSubmit" Runat=server Text="Submit"></asp:Button>

As well, your <% ... %> ASP tags show that you did NOT provide the client side Javascript, either.

Run your code in the browser, then View -> Source and copy and paste what shows THERE.

Lee
 
I know all the calls are for the purpose of better help. But if that is taken as a matter of prime working principle of the forum, I would ask myself: Can one ever talk philosophy again by reading the original Greek text of the old masters? or theology from the dated Hebrew version of the Bible or Koran in Arabic? or if it is only possible to make the world turn by all starting from their English translation?
 
If I discuss philosphy primarily in English, but throw terms in where the definitions/meanings are known only to me (even if the language itself is understood by others in the group), I am "as a sounding brass or tinkling cymbal", so to speak - making unintelligible noise. :)#

Since the actual value/meaning of lblWarning.ClientID can only be determined by seeing what the script produces, it's not unreasonable to expect to see the final result. Showing the HTML output will display errors caused by misspelled scripting variables, incorrect variables referenced, and other things that won't be as obvious (or visible at all) by looking over script segments in the langue du jour.

Lee
 
Hello,

sorry for the delay, i can only post here while i'm at work.

I hope this is what you need.

Code:
<tr id="tl_template__ctl0_Dates" Style="Display:none">
			<td>&nbsp;</td>
			<td class="tablelightbg"><p>
				<span class="required"><label for="tl_template__ctl0_rb1">After 1 week</label><input id="tl_template__ctl0_rb1" type="radio" name="tl:template:_ctl0:dates" value="rb1" /></span>  
				<span class="required"><label for="tl_template__ctl0_rb2">After 2 weeks</label><input id="tl_template__ctl0_rb2" type="radio" name="tl:template:_ctl0:dates" value="rb2" /></span>  
				<span class="required"><label for="tl_template__ctl0_rb3">After 1 month</label><input id="tl_template__ctl0_rb3" type="radio" name="tl:template:_ctl0:dates" value="rb3" /></span>
				<span class="required"><label for="tl_template__ctl0_rb4">After 2 months</label><input id="tl_template__ctl0_rb4" type="radio" name="tl:template:_ctl0:dates" value="rb4" /></span>
				<span id="tl_template__ctl0_lblWarning" style="color:Red;"></span>
			</p></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td align="left"><input type="submit" name="tl:template:_ctl0:btnSubmit" value="Submit" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="tl_template__ctl0_btnSubmit" class="submit" onmouseup="return CheckDateUpdate()" />&nbsp;&nbsp;<input type="submit" name="tl:template:_ctl0:btnCancel" value="Cancel" id="tl_template__ctl0_btnCancel" class="submit" /></td>
		</tr>

Code:
function CheckDateUpdate()
		{
			var radio1 = document.getElementById('tl_template__ctl0_rbYesDates');
			var radio2 = document.getElementById('tl_template__ctl0_rbNoDates');
			var label = document.getElementById('tl_template__ctl0_lblWarning');
			
			if (radio1.checked == false && radio2.checked == false)
			{
				document.getElementById('tl_template__ctl0_Dates').style.display = 'inline';
				label.text = "A choice whether to update or not must be made."
				return false;
			}
			else
			{
				document.getElementById('tl_template__ctl0_Dates').style.display = 'none';
				label.text = ""
				return true;
			}
		}
 
When I alert the "label.text" i can see its text fine, but i do not see it on the browser and most importantly the click event continues.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top