I'm not able to access the variable in my .js file
the code i have at the top of the page is:
<script type="text/javascript">
privilage = '<%=Session["privilage"]%>';
</script>
then i want to access privilage in my .js file.
i just want to alert this at the moment. would i be able to do this?
thanks
You have to store session Value in HiddenField.
After that You can Access the HiddneFieldValue in your JS
<script type="text/javascript">
document.getElementById('hdnField').value = '<%=Session["privilage"]%>';
</script>
Just use:
var privilage = '<%=Session["privilage"]%>';
or try:
alert(privilage);
It will display your Session value
I use it this way.
<asp:TextBox ID="txtValue" runat="server" CssClass="txtValue" style="display: none;" />
Then I use jQuery to access the value.
<script>
var txtValue = $(".txtValue").val();
</script>
Or even on a control.
<asp:LinkButton ID="lnkPrint" runat="server" CausesValidation="true"
CommandName="Print" CommandArgument='<%# Bind("PrintData") %>'
Text="<img src='/images/print_on.png' onmouseover='cursor: pointer;'
class='PrintButton' />" ToolTip="Print" OnClientClick="if ($('.txtValue').val()
!= '1') { $('.txtValue').val('1'); alert('Warning: Please enable pop-ups for
this site!'); }" />
This method survives ajax and postbacks.
Cheers
use
<script type="text/javascript">
var privilage = '<%=Session["privilage"]%>';
</script>
Related
I am using preloader in my aspx page but my preloader blocks asp.net buttons,
how do I solve this?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
document.write('<script src="/dizin/dosyalar/bs/js/vendor/jquery.min.js"><\/script>')</script>
<script src="/dizin/dosyalar/bs/js/bootstrap.min.js"></script>
<script>
$(window).load(function(){$('#status').fadeOut();$('#preloader').delay(350).fadeOut('slow');$('body').delay(350).css({'overflow':'visible'});})
</script>
<div class="gnl-loading" id="preloader"></div>
<asp:ImageButton ID="ebulten" runat="server" OnClick="ebulten_OnClick" CssClass="btn btn-default footerbtn" ImageUrl="/dizin/site/img/index/btn.png" />
Javascript codes solved by getting inside the page
I got this error from jquery version
Check your old jquery codes and rewrite. Its will be work
am trying to show a loading div on button click, but it is not working at the moment.
Javascript :
<script type="text/javascript">
$(document).ready(function (e) {
$('#BtnSend').click(function () {
$('#<%= loading.ClientID %>').toggle("slow");
});
});
</script>
Div:
<div id="loading" class="Loading" runat="server" visible="false">
<div class="loadingImg">
<img src="../Images/loading.gif" alt="loading" />
</div>
</div>
Button:
<asp:Button ID="BtnSend" runat="server" Text="SEND"
onclick="BtnSend_Click" CssClass="pressbutton2" Height="36px" ClientIDMode="Static" />
the div is set to runat server so that I can change its visibility also through code.
Use the onClientClick for the asp button. Then make the jquery function that you ahve called BtnSend_Click
If you want to do it via Client side:
jQuery
function BtnSend_Click () {
$('#<%= loading.ClientID %>').toggle("slow");
}
ASP Button
<asp:Button ID="BtnSend" runat="server" Text="SEND"
onClientClick="BtnSend_Click" CssClass="pressbutton2" Height="36px" ClientIDMode="Static" />
If you want to do it via the server:
C#
protected void BtnSend_Click(object sender, EventArgs e){
loading.Visibility = 'visible' //not sure on syntax to show it in code behind off the top my head
}
ASP Button
<asp:Button ID="BtnSend" runat="server" Text="SEND"
onClick="BtnSend_Click" CssClass="pressbutton2" Height="36px" ClientIDMode="Static" />
The ASP.Net AJAX library has an UpdateProgress control that sounds like it would fit your needs.
I've tried adding in a prevent default, as the code as described below would postback before the loading div was shown otherwise.
<script type="text/javascript">
$(document).ready(function (e) {
$('#<%= BtnSend.ClientID %>').click(function (e) {
e.preventDefault();
$('#<%= loading.ClientID %>').toggle("slow");
});
});
</script>
Another thing I've noticed is you have set Visible="false":
<div id="loading" class="Loading" runat="server" visible="false">
This means the div doesn't exist as its not output from the server side. Look in the view source when the page loads, it wont be there and hidden, its just not there. Remove the visible="false" and use CSS to hide it to start off with.
<script type="text/javascript">
$(document).ready(function () {
$('input[name="time"]').ptTimeSelect();
});
</script>
the above script is working on this:
<input name="time" value="" /></td>
But not working on this...
<asp:TextBox ID="time" name='time' runat="server"></asp:TextBox>
Please use following code
<script type="text/javascript">
$(document).ready(function () {
var id='<%=time.clientid%>'
$('#'+id).ptTimeSelect();
});
</script>
and let me know if this does not work.
From what I remember of ASP.NET is that it modifies the ID and name of an element to ensure it's always unique. The end result of the <asp:TextBox> may be something like:
<input name="ctr_0102_time" />
The best bet is to check the element's source on the live page to determine what attributes it has. If it does have a random identifier then you should probably base it on a specific class:
<input class="time" />
<asp:TextBox CssClass="time"></asp:TextBox>
$('input.time') ...
The other thing that may cause this to break are post backs. Post backs in ASP.NET do not re-ready the document, they simply reload the page. Instead of using $(document).ready() use:
function pageLoad() { ... }
try this:
<script type="text/javascript">
$(document).ready(function () {
$('[id$=time]').ptTimeSelect();
});
</script>
I am using datapicker jquery but it is not able to get Input Id in C#.If i give runat=server ,i can call the input id in c#,but it does not work in page. Can anyone help me for that, I am new to Dnn. Any answer would be appreciated. Thank you.
enter code here
<div class="demo">
<p>Date: <input id="datepicker" type="text" />
</p>
</div>
Use TextBox with DatePicker
<asp:TextBox ruat="server" ID="txtDate" ></asp:TextBox>
To access it use ClientID
<script type="text/javascript">
$(function() {
$("#<%= txtDate.ClientID %>").datepicker();
});
</script>
EDIT: Based on the comments
After defining your txtDate in aspx page with runat="server" you can access it in code behind like:
string value = txtDate.Text;
yep because when you add runat server the id get renamed by asp try using somethink like this
setting the client id mode static if you are using .net 4.0
or if you do not use .net 4.0 then try this
<p>Date: <input id="datepicker" ClientIDMode="Static type="text" runat="server" />
or if you do not use .net 4.0 then try this
$("#<%= datepicker.ClientID %>").datepicker();
You can use CssClass of textbox to get datepicker in following way:
<asp:TextBox ID="txtDate" runat="server" CssClass="DatepickerInput" />
You can use jquery code in following way:
$(document).ready(function () {
$(".DatepickerInput").datepicker({ dateFormat: 'dd/mm/yy' });
});
<% string s=LinkButton_ID.Text; %>
<asp:LinkButton ID="LinkButton_ID" runat="server" Text="LinkButton_Text" onclientclick="JscriptFunction(...)">
</asp:LinkButton>
I want to send the "s" as parameter to JscriptFunction. I try JscriptFunction(<% s %>); but doesnt work. Do you have any suggestions? thank you
Try this:
JscriptFunction('<%= s %>');
Don't forget to quote the text value in your JS function call.
EDIT:
I didn't notice that your call to JscriptFunction is inside your server tag. If you don't have access to jQuery, the easiest way to pass the client-side text of the button is probably this:
onclientclick="JscriptFunction(this.innerHTML)"
Here's an example working on jsFiddle.
You can also pass the client-side ID of the control and manipulate the value using JavaScript. Make sure you have ClientIDMode="Predictable" or ClientIDMode="Static" set on the control if you do it this way.
You'll need to declare your code section to be javascript, and then you need to output the asp.net/c# value as a string. The easiest way is something like:
<script type="text/javascript">
var s = <% Response.write(LinkButton_ID.Text); %>;
//do your other javascript stuff
</script>
or
<script type="text/javascript">
var s = <%= LinkButton_ID.Text %>;
//do your other javascript stuff
</script>
If you needed to do more logic around this, you could also stick a literal control there and output to it in the code-behind:
<script type="text/javascript">
var s = <asp:literal id="litMyValue" runat="server">;
//do your other javascript stuff
</script>
Simple way u can pass/ instead you can use it in the function itself
like
<script>
function JscriptFunction()
{
var s = <%= LinkButton_ID.Text %>;
// do what you want here.
}
</script>
<asp:LinkButton ID="LinkButton_ID" runat="server" Text="LinkButton_Text" onclientclick="JscriptFunction();"></asp:LinkButton>