Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

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.
Avatar of Mrunal
Mrunal
Flag of India image

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.
create an event in code behind

RadioButton2_SelectedIndexChange

and here show your msg
Avatar of Mike Eghtebas

ASKER

Hi Mrunal,

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

Thanks for the link I will read through.

Mike
king2002,

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

Thanks,

Mike
my thoughts are: why not disable that radio button....
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
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
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

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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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