tags:

views:

40

answers:

1

Hi

I have a view page that has two DIV tags. If the session[UserType] = ‘Guest’ , then I need to diplay Guest DIV Section.

Else
If session[userType] = ‘Logged’

, then I don’t need to diplay Guest DIV Section.

<div id="Logged" >
    <div class="txtContent">
        <label for="product" class="Form_Label">product:<em>*</em></label> 
        <%= Html.DropDownList("product", " -- Select one -- ")%>
    </div>
</div>

<div id="Guest">
    <label for="DeliveryMethod">Delivery Method: </label>
    <select name="DeliveryMethod" id="Select1" style="width: 100px">
        <option value="email">Email</option>
        <option value="fax">Fax</option>
        <option value="mail">Mail</option>
    </select>
</div>

Appreciate your responses.

Thanks

+1  A: 

Sounds like you could do with either jQuery or a partialView.

My flavour would be to display a partial view based on the decision point.

Remember that your page shouldn't have any logic in it so you may want to write a helper to make the decision for you.

As an alternative you could render the page and then call a jQuery method that will return a partial view based on the parameter you send it.

If you require code please add a comment and I'll post some.

Edit

@Rita, if you're happy to have the HTML present on the page and you only want to hide/show the divs then here is the code for that;

<input type="hidden" id="hdnSessionValue" value="<%=session[UserType]">

<div id="Guest">
    <label for="DeliveryMethod">Delivery Method: </label>
    <select name="DeliveryMethod" id="Select1" style="width: 100px">
        <option value="email">Email</option>
        <option value="fax">Fax</option>
        <option value="mail">Mail</option>
    </select>
</div>

Then you have the following jQuery;

<script language="javascript">
  $(document).ready( function () {
    if ( $('#hdnSessionValue').val() == "Guest")
      $('#Guest').show();
    else
      $('#Guest').hide();
  } );
</script>

Edit2

Based on the amount of HTML you have to hide/show I don't think a jQuery postback is required.

griegs
Yup. I need code. Thankks Griegs. Appreciate your time. I am trying to put my view code here. Somehow it is not displaying here on this Stackoverflow.<div id="Registered" > <div class="txtContent"> <label for="product" class="Form_Label">product:<em>*</em></label> <%= Html.DropDownList("product", " -- Select one -- ")%> </div></div><div id="Guest"> <label for="DeliveryMethod">Delivery Method: </label> <select name="DeliveryMethod" id="Select1" style="width: 100px"> <option value="email">Email</option>
Rita
I would prefer to go with the alternative way.i.e. load it using JQuery method
Rita
Thanks griegs. This is exactly what i want.
Rita
Awesome. I implemented. Worked perfect.
Rita