[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

asp.net c#

Posted on 2014-07-20
11
Medium Priority
?
159 Views
Last Modified: 2014-07-27
Here is a javascript that fires okay
 function handleRollup(myRadio) {
           alert('Monthly option not available at this point.');
}

using:
<asp:Panel ID="optRollup" runat="server" OnChange="javascript:updateRollup();" >  

<asp:RadioButton ID="RadioButton1" name="Rollup" Text="Monthly" runat="server"  onclick="javascript:handleRollup(this);" value="1" GroupName="Rollup" />

<asp:RadioButton ID="RadioButton2"  name="Rollup" Text="YTD" Checked="true" runat="server"  onclick="javascript:handleRollup(this);" value="2" GroupName="Rollup"/>

</asp:Panel>

Open in new window

Question: How can I replace this js code with a server-side event to give the message?

Thank you.
0
Comment
Question by:Mike Eghtebas
11 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 40208329
Fire radio button's server side event - OnSelectedIndexChanged
Reference:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.onselectedindexchanged%28v=vs.110%29.aspx

then in that function, write below code:

Response.Write("<script type='javascript'>alert('Monthly option not available at this point.');</script>");

Hope this helps you.
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 40208341
create an event in code behind

RadioButton2_SelectedIndexChange

and here show your msg
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40208342
Hi Mrunal,

I was looking for c# code without any java script if possible.

Thanks for the link I will read through.

Mike
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40208345
king2002,

Could you give me a bit more detail? Steps (no matter how simple) could help.

Thanks,

Mike
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40208363
my thoughts are: why not disable that radio button....
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 40209811
This is a partial solution:
    <asp:Panel ID="optRollup" runat="server" OnChange="javascript:updateRollup();" >  
        <asp:RadioButton ID="rdo_Monthly" name="Rollup" Text="Monthly" runat="server"  value="1" GroupName="Rollup" oncheckedchanged="CheckedChanged" />
        <asp:RadioButton ID="rdo_YTD"  name="Rollup" Text="YTD" Checked="true" runat="server" value="2"  GroupName="Rollup" oncheckedchanged="CheckedChanged"/>
    </asp:Panel>
    <asp:Button ID="btnProcess" runat="server" Text="Process" />

Open in new window

The oncheckedchanged event will fire when the radiobutton changes from not selected to selected (or not selected to selected).  When the user clicks the "Process" button, the server side events will be processed and you will have code something like this:
protected void CheckedChanged(object sender, EventArgs e)
{
    if (rdo_Monthly.Checked)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "Disabled", @"alert('Monthly option not available at this point.');", true);
        return;
    }

    //Other non-monthly processing may occur here
}

Open in new window


A similar type of server side processing could occur on the button click event
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40210729
Hi AngelIII,

re:> my thoughts are: why not disable that radio button....

There are two reasons why I am not disabling the radio button:
1. Disabling this control is; but I want to learn how to do by first giving a message and then reverting back to YTD option.
2. It is better to communicate to the user Monthly selection is coming up; otherwise they will think that something is not working.
------------------
Hi MogalManic,

I have no been able to implement it yet. I am still working on it. At one point, I messed the entire application most likely because I did something wrong following your method. I will update you soon.

With regards to both experts,

Mike
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40210761
I understand reason 1 perfectly, but I had learned that a disabled control is more intuitive to a user than an enabled control that reports 'funciton is not implemented'

for reason 2 there is a simple way: put the info into the label, explaining in writing to the user why the control is disabled (see above)


anyhow, I would stay with the javascript, but instead of having the same "handleRollup" for both radios, I would put a dedicated function for the one(s) that have a message and need to select the other radio instead...
untested code, just for the ideas...
 function handleRollupDisabled(myRadio, otherRadioID) 
{
           alert('Monthly option not available at this point.');
           document.getElementById(otherRadioID).checked = true;
}
function handleRollupNormal(myRadio) 
{
           alert('this option is available');
}

Open in new window


 
<asp:Panel ID="optRollup" runat="server" OnChange="javascript:updateRollup();" >  

<asp:RadioButton ID="RadioButton1" name="Rollup" Text="Monthly" runat="server"  onclick="javascript:handleRollupDisabled(this, 'RadioButton2');" value="1" GroupName="Rollup" />

<asp:RadioButton ID="RadioButton2"  name="Rollup" Text="YTD" Checked="true" runat="server"  onclick="javascript:handleRollup(this);" value="2" GroupName="Rollup"/>

</asp:Panel>

Open in new window

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40210817
a3,

Thank you for the solution. Another thing I never mentioned is this particular company for security reason doesn't like/ allow use of java script (I don't agree with them but...).

So, I was eager to know if this functionality could be handled without any use of js. Is there any way one can do this using c#. This obviously adds extra load because it has to be on the server rather than on the client side but it is good to know the option.

I suppose if I double click on the control, it should give me an even to write something there. For what to write I need your help.

Thanks again,

Mike
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 40210887
if javascript is not allowed/not liked by the company rules, I really think you should go my first proposal: disable the control, and set the 2nd radio as checked by default...
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 40222970
I will post this question again trying to get what I intend to accomplish. Which is:

Without having the control disable and pre-set, give a message to the user and then set the control as desired.

Thanks,

Mike
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question