|
Why would you? Without a great deal more complexity you can't. There are other ways to accomplish your task I'm sure, why don't you tell us what you want to accomplish and what you think you are gaining by trying to insert code in the manner.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I am trying to create a 'Content Management System' type of app. I want to add 'pages' dynamically with server controls markup and attach them to events.
So bascially, I want to be able to write an entire asp.net page w/ server side scripts in text and execute it at run-time.
What I have been able to accomplish so far is creating the control. However, hooking on to the events is whats causing me problems.
|
|
|
|
|
You do understand that SERVER side scripts are processed on the SERVER? Injecting them in the page on the server is not going to accomplsih anything.
Take a look at other CMS applications such as SharePoint and you will fined they use templates and page level parsers to inject dynamic controls into the output stream.
To add a control and event handler to the page you do something like this.
protected void OnInit(...)
{
Button myBtn = new Button();
myBtn.Text = "Some text";
myBtn.Click += new OnClick;
Page.Controls.Add(myBtn);
}
protected void OnClick(object sender, EventArgs e)
{
...
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I understand the server side scripts are executed in the server but I figured that there has to be a point during the life cyle where the markup, including the scripts, are parsed and compiled into dlls. This is where I wanted to inject my text. Seems like I may have to find another solution.
Thanks for your input.
|
|
|
|
|
I think what you're trying to do is something along these lines (excuse my VB code - you'll have to trasnlate it yourself if you want)
First, add a placeholder control on the form where you want to add the new control, and also a literal (just so we can test things_ -eg:
<asp:PlaceHolder runat="server" ID="phHere"></asp:PlaceHolder>
<p><asp:Literal runat="server" ID="litClick"></asp:Literal></p>
Then in your code behind, add this:
Private Sub btnNewButton_Click(ByVal Sender As Object, ByVal e As EventArgs)
litClick.Text = "Clicked!"
End Sub
and in the Page_Load event, add this:
Dim btn As New Button
btn.ID = "btnNewButton"
btn.Text = "My new button"
AddHandler btn.Click, AddressOf btnNewButton_Click
phHere.Controls.Add(btn)
|
|
|
|
|
Thanks for your response. Thats not exactly what I am trying to do. I want to be able to add dynamic code after my app has been build... just lke VSA.
|
|
|
|
|
I’m developing a .NET/C# application software for an instrument which has a built-in PC (Core 2 CPU/2.66GZ/4GB RAM) and will have access to the Internet from behind the facility IT firewall. To support remote device maintenance via Intetnet using browser, I want to run a web site locally IIS hosted on the instrument PC. Apparently, this site is for authorized user only (could be anywhere on the Inernet). I know security is the major problem to deal with in this scenario. To reduce the surface of attach, can I lock down the allowable IP range to just one IP address where the service user is? This one IP address will be made configurable. Is this a viable approach to secure the web site with the least cost?
Just googled that .htaccess file can be created in webroot to block IP ranges. Will this still allow scripts to access the site
Sorry, .htaccess is available on Apache server only. What's equivalent on IIS?
modified on Saturday, June 19, 2010 10:19 PM
|
|
|
|
|
From IIS Manager; (This sequence is 2003 Server, but dare say others are similiar)
1) Right Click the Web Site and choose Properties
2) Select the Directory Security Tab
3) Click Edit in the IP Address and Domanin Name restrictions panel
4) Grant/Deny relevant domains/ip as required.
|
|
|
|
|
Is it possible to do it in code? e.g. after receiving an allowable IP address, place it somewhere in a config file?
|
|
|
|
|
Yeah, it's possible to do in code using WMI, you can read here[^] how to do it. You should change binding for the application.
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
|
I was recently going through one site and the url of that site was www.abc.com/default.asp
But that site was quite techy - so it can't be of that old asp days. Shouldn't it be .aspx in the end ? Or am i missing something.
Thank You
Andyyy
|
|
|
|
|
If they are hosting the site on their own server (or at least a server to which they have full admin access) then they could map asp files to .net - this is a simple setting in IIS. (Though one has to wonder why anyone would want to do this.)
But otherwise, there are still a lot of sites out there still in clasic asp. "If it ain't broke, don't fix it" is a good maxim in any field. Sometimes the work, time and money involved in upgrading a site is more than it's worth.
|
|
|
|
|
Hi All! I am trying to process several requests to a website, performing posts of data and processing page results. I'm finding it seems very inefficient, and actually it seems to take longer to process the request than compared to typing in manually.
Looking at the code below it appears there isn't a way to simplify or move initialization of objects to another method, rather than performing it each request is made (the requests are being made to the same website).
Here is my code below.
Thanks for all your help!
private string ProcessFormPOST(string strURL, string strFormData)
{
try
{
byte[] buffer = Encoding.UTF8.GetBytes(strFormData);
string proxy = null;
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strURL);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buffer.Length;
req.Proxy = new System.Net.WebProxy(proxy, true);
req.CookieContainer = new System.Net.CookieContainer();
System.IO.Stream reqst = req.GetRequestStream();
reqst.Write(buffer, 0, buffer.Length);
reqst.Close();
System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.Stream resst = res.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(resst);
return sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
}
|
|
|
|
|
Hi you experts, I want to write a Googlemap than UserControl so that the
Control may often be involved in a Page.
Lattitude, Longtiude should be enter. Creates should be a Linkbutton activated
a ModalPopup in which the inside is GoogleMap
What do you think? Do you have other ideas?
|
|
|
|
|
There are various controls already available for this just search for "Google Maps ASP control", here is one example returned; http://en.googlemaps.subgurim.net/[^]
You could also roll your own, if you look at the googlemaps api (Search google for the api site link) everything looks pretty straight forward.
There are also a couple of Articles on CodeProject that relate to google maps.
You could also use Bing Maps and likewise there is also a bunch of stuff already out there for it.
Cheers,
|
|
|
|
|
|
As with anything on the net, you have to read the relevant license to see if you can freely use it.
There is usually a terms of use / license quoted somewhere. All the articles on CP should have the license referenced at the bottom.
|
|
|
|
|
I am developing an asp.net data driven application using VS2010. Whenever I use the debugger and try to visualise a data table i am getting a function evaluation timeout error. My application is targeted for .NET 2.0.
Anyone came across this issue?
Thanks and regards,
Chris
|
|
|
|
|
Hi
Can I put a hyperlink on my web page and make it open at a random page?
|
|
|
|
|
You can't just get any random page existing in the universe, there is no way of generating the URL of a page randomly, however you can use a random index into a list of candidate pages.
Example: my articles[^] page, which gets generated from a database table, has a "random article" key which basically chooses a random row of that table.
|
|
|
|
|
Hi All,
Can i set a session value in javascript File and access it from code behind file in asp.net and C#
Thanks,
Amit
|
|
|
|
|
Amit Patel1985 wrote: Can i set a session value in javascript File and access it from code behind file in asp.net and C#
No, you cannot set a session in JavaScript. Sessions are server side and JavaScript is fully client side.
|
|
|
|
|
Its not possible, but you can have a workaround for this, store the value in a hidden field using javascript and add the hidden field value to session at server side.
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
protected void _bindTopicPage()
{
int _lowerLimit = _pageIndex * _pageCount;
int _upperLimit = (_pageIndex * _pageCount) + (_pageCount - 1);
string _str;
if (Convert.ToInt32(Request.QueryString["UserID"]) != 0)
{
_str = "SELECT dbo.tblUser.FirstName, dbo.tblUserMessage.SubmittedOn, dbo.tblUserProfile.UserID, dbo.tblUserProfile.ImageUrl, dbo.tblUserMessage.Message FROM dbo.tblUser INNER JOIN dbo.tblUserMessage ON dbo.tblUser.ID = dbo.tblUserMessage.MessageFrom INNER JOIN dbo.tblUserProfile ON dbo.tblUserMessage.MessageFrom = dbo.tblUserProfile.UserID where dbo.tblUserMessage.MessageTo=" + Convert.ToInt32(Request.QueryString["UserID"]) + " order by [tblUserMessage].ID desc";
}
else
{
_str = "SELECT dbo.tblUser.FirstName, dbo.tblUserMessage.SubmittedOn, dbo.tblUserProfile.UserID, dbo.tblUserProfile.ImageUrl, dbo.tblUserMessage.Message FROM dbo.tblUser INNER JOIN dbo.tblUserMessage ON dbo.tblUser.ID = dbo.tblUserMessage.MessageFrom INNER JOIN dbo.tblUserProfile ON dbo.tblUserMessage.MessageFrom = dbo.tblUserProfile.UserID where dbo.tblUserMessage.MessageTo=" + Convert.ToInt32(Session["UserID"]) + " order by [tblUserMessage].ID desc";
}
SqlDataAdapter da = new SqlDataAdapter(_str, con);
DataSet ds = new DataSet();
da.Fill(ds);
StringBuilder _sb = new StringBuilder();
int _count = ds.Tables[0].Rows.Count;
ViewState["_cccount"] = ds.Tables[0].Rows.Count;
if (_upperLimit >= _count)
_upperLimit = _count - 1;
for (int i = _lowerLimit; i <= _upperLimit; i++)
{
_sb.Append("<div class='scrapGrayBg'>");
_sb.Append("<div class='scrapUser'><a href='Userprofile.aspx?UserID=" + ds.Tables[0].Rows[i]["UserID"] + "'><img src='cropimages/" + ds.Tables[0].Rows[i]["ImageUrl"] + "' width='50px' height='50px' alt='' class='imgBdr' /></a><br /><input name='' id='chk"+i+"' runat='server' type='checkbox' class='scrapCheck' value='' /></div>");
_sb.Append("<div class='scrapRt'>");
_sb.Append("<div class='scrapHdSce'>");
_sb.Append("<div class='scrapHd'><a href='Userprofile.aspx?UserID=" + ds.Tables[0].Rows[i]["UserID"] + "'>" + ds.Tables[0].Rows[i]["FirstName"] + ":</a></div>");
_sb.Append("<div class='scrapDelet'>" + ShowDateTime(ds.Tables[0].Rows[i]["SubmittedOn"]) + "<a href='#'><img src='images/delete_sml.gif' alt='' width='43' height='19' class='scrapDelImg' /></a></div>");
_sb.Append("<div class='clear'></div>");
_sb.Append("</div>");
_sb.Append("<div>" + ds.Tables[0].Rows[i]["Message"] + "</div>");
_sb.Append("<div><a href='javascript://' onclick='showText("v" + (i + 1) + "")'><img src='images/reply_sml.gif' alt='' width='50' height='18' class='replyBtn'/></a><br />");
_sb.Append("<div class='replyInpBdr' id='v" + (i + 1) + "' style='display:none;'><textarea name='' id='txtpostreply" + i + "' runat='server' cols='' rows='' class='replyTextArea'></textarea><br />");
_sb.Append("<div class='fl'><a href='javascript:fnAccept(" + ds.Tables[0].Rows[i]["UserID"] + "," + Convert.ToInt32(Session["UserID"]) + "," + i + ")'><img src='images/post_scrap.jpg' alt='' vspace='5' align='top' /></a></div>");
_sb.Append("<div class='fr'><a href='javascript://' onclick='hideText("v" + (i + 1) + "")'><img src='images/close_btn.gif' alt='' vspace='5' /></a></div>");
_sb.Append("<div class='clear'></div>");
_sb.Append("</div>");
_sb.Append("<div class='replyInpBdr' id='divmsg" + (i + 1) + "' style='display:none; color:#FF0000; margin:5px 0 0 0;'> Your message has been send successfully.");
_sb.Append("</div>");
_sb.Append("</div>");
_sb.Append("</div>");
_sb.Append("<div class='clear'></div>");
_sb.Append("</div>");
}
divdetail.InnerHtml = _sb.ToString();
_sb.Remove(0, _sb.Length);
int NoOfPage = _count / 8;
if (_count % 8 != 0)
NoOfPage = NoOfPage + 1;
_sb.Append("<div class='bradcrum' style='padding:4px;'>");
for (int j = 0; j < NoOfPage; j++)
{
if (j == Convert.ToInt32(Request.QueryString["PageNo"]))
_sb.Append("<a href='Scrap.aspx?PageNo=" + j + "' class='sel'>" + (j + 1) + "</a>");
else
_sb.Append("<a href='Scrap.aspx?PageNo=" + j + "'>" + (j + 1) + "</a>");
}
_sb.Append("</div>");
divPagenation.InnerHtml = _sb.ToString();
}
I am taking a input type checkbox.we want checkbox id's on button click.
i am using no control only use div.
I have used this
CheckBox chk = (CheckBox)page.FindControl("chk0");
it showing null.
so please help me????
|
|
|
|