asp.net c#

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.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MrunalCommented:
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
Kamal KhaleefaInformation Security SpecialistCommented:
create an event in code behind

RadioButton2_SelectedIndexChange

and here show your msg
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi Mrunal,

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

Thanks for the link I will read through.

Mike
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
king2002,

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

Thanks,

Mike
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
my thoughts are: why not disable that radio button....
0
MogalManicCommented:
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
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.